Fixed isfinite with C++98 compilers #343

This commit is contained in:
Christophe Riccio 2015-07-19 16:32:36 +02:00
parent 056d6bd95e
commit 76bd630bbd
4 changed files with 25 additions and 2 deletions

View File

@ -84,6 +84,7 @@ namespace glm
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec4<T, P> atan2(const tvec4<T, P>& x, const tvec4<T, P>& y){return atan(x, y);} //!< \brief Arc tangent. Returns an angle whose tangent is y/x. The signs of x and y are used to determine what quadrant the angle is in. The range of values returned by this function is [-PI, PI]. Results are undefined if x and y are both 0. (From GLM_GTX_compatibility)
template <typename genType> GLM_FUNC_DECL bool isfinite(genType const & x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_DECL tvec1<bool, P> isfinite(const tvec1<T, P>& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_DECL tvec2<bool, P> isfinite(const tvec2<T, P>& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_DECL tvec3<bool, P> isfinite(const tvec3<T, P>& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_DECL tvec4<bool, P> isfinite(const tvec4<T, P>& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)

View File

@ -46,10 +46,21 @@ namespace glm
# elif GLM_COMPILER & GLM_COMPILER_GCC && GLM_PLATFORM & GLM_PLATFORM_ANDROID
return _isfinite(x) != 0;
# else
return x >= std::numeric_limits<genType>::min() && x <= std::numeric_limits<genType>::max();
if (std::numeric_limits<genType>::is_integer || std::denorm_absent == std::numeric_limits<genType>::has_denorm)
return std::numeric_limits<genType>::min() <= x && std::numeric_limits<genType>::max() >= x;
else
return -std::numeric_limits<genType>::max() <= x && std::numeric_limits<genType>::max() >= x;
# endif
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec1<bool, P> isfinite(
tvec1<T, P> const & x)
{
return tvec1<bool, P>(
isfinite(x.x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<bool, P> isfinite(
tvec2<T, P> const & x)

View File

@ -59,7 +59,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
- Added <glm/gtx/hash.hpp> to perform std::hash on GLM types #320
- Added <glm/gtx/wrap.hpp> for texcoord wrapping
- Added static components and precision members to all vector and quat types #350
- Added .gitignore #349
- Added .gitignore #349
##### Improvements:
- Changed usage of __has_include to support Intel compiler #307
@ -75,6 +75,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
- Fixed specifier removal by 'std::make_pair<>' #333
- Fixed perspective fovy argument documentation #327
- Removed -m64 causing build issues on Linux 32 #331
- Fixed isfinite with C++98 compilers #343
##### Deprecation:
- Removed integer specification for 'mod' in GTC_integer #308

View File

@ -35,5 +35,15 @@ int main()
{
int Error(0);
Error += glm::isfinite(1.0f) ? 0 : 1;
Error += glm::isfinite(1.0) ? 0 : 1;
Error += glm::isfinite(-1.0f) ? 0 : 1;
Error += glm::isfinite(-1.0) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::vec4(1.0f))) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::dvec4(1.0))) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::vec4(-1.0f))) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::dvec4(-1.0))) ? 0 : 1;
return Error;
}