From 76bd630bbd10105952e079df47b3c992e5e74473 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 19 Jul 2015 16:32:36 +0200 Subject: [PATCH] Fixed isfinite with C++98 compilers #343 --- glm/gtx/compatibility.hpp | 1 + glm/gtx/compatibility.inl | 13 ++++++++++++- readme.md | 3 ++- test/gtx/gtx_compatibility.cpp | 10 ++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/glm/gtx/compatibility.hpp b/glm/gtx/compatibility.hpp index 6a3623be..5b3f0513 100644 --- a/glm/gtx/compatibility.hpp +++ b/glm/gtx/compatibility.hpp @@ -84,6 +84,7 @@ namespace glm template GLM_FUNC_QUALIFIER tvec4 atan2(const tvec4& x, const tvec4& 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 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 GLM_FUNC_DECL tvec1 isfinite(const tvec1& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility) template GLM_FUNC_DECL tvec2 isfinite(const tvec2& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility) template GLM_FUNC_DECL tvec3 isfinite(const tvec3& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility) template GLM_FUNC_DECL tvec4 isfinite(const tvec4& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility) diff --git a/glm/gtx/compatibility.inl b/glm/gtx/compatibility.inl index decc26c2..77f99d13 100644 --- a/glm/gtx/compatibility.inl +++ b/glm/gtx/compatibility.inl @@ -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::min() && x <= std::numeric_limits::max(); + if (std::numeric_limits::is_integer || std::denorm_absent == std::numeric_limits::has_denorm) + return std::numeric_limits::min() <= x && std::numeric_limits::max() >= x; + else + return -std::numeric_limits::max() <= x && std::numeric_limits::max() >= x; # endif } + template + GLM_FUNC_QUALIFIER tvec1 isfinite( + tvec1 const & x) + { + return tvec1( + isfinite(x.x)); + } + template GLM_FUNC_QUALIFIER tvec2 isfinite( tvec2 const & x) diff --git a/readme.md b/readme.md index a30d3017..7f0a3bab 100644 --- a/readme.md +++ b/readme.md @@ -59,7 +59,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Added to perform std::hash on GLM types #320 - Added 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 diff --git a/test/gtx/gtx_compatibility.cpp b/test/gtx/gtx_compatibility.cpp index bd727318..ee577b06 100644 --- a/test/gtx/gtx_compatibility.cpp +++ b/test/gtx/gtx_compatibility.cpp @@ -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; }