From dc897972751a16fc91198cb7d11233e2379ddcd5 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 17 Jul 2016 01:02:30 +0200 Subject: [PATCH] - Added quaternion version of isnan and isinf #521 --- glm/gtc/quaternion.hpp | 23 +++++++++++++++++++++++ glm/gtc/quaternion.inl | 16 ++++++++++++++++ readme.md | 1 + test/core/core_func_common.cpp | 2 +- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 85ee7efc..b4762a87 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -368,6 +368,29 @@ namespace glm /// @see gtc_quaternion template GLM_FUNC_DECL tvec4 notEqual(tquat const & x, tquat const & y); + + /// Returns true if x holds a NaN (not a number) + /// representation in the underlying implementation's set of + /// floating point representations. Returns false otherwise, + /// including for implementations with no NaN + /// representations. + /// + /// /!\ When using compiler fast math, this function may fail. + /// + /// @tparam genType Floating-point scalar or vector types. + template + GLM_FUNC_DECL tvec4 isnan(tquat const & x); + + /// Returns true if x holds a positive infinity or negative + /// infinity representation in the underlying implementation's + /// set of floating point representations. Returns false + /// otherwise, including for implementations with no infinity + /// representations. + /// + /// @tparam genType Floating-point scalar or vector types. + template + GLM_FUNC_DECL tvec4 isinf(tquat const & x); + /// @} } //namespace glm diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 06257994..60cae12f 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -777,6 +777,22 @@ namespace detail Result[i] = x[i] != y[i]; return Result; } + + template + GLM_FUNC_QUALIFIER tvec4 isnan(tquat const& q) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isnan' only accept floating-point inputs"); + + return tvec4(isnan(q.x), isnan(q.y), isnan(q.z), isnan(q.w)); + } + + template + GLM_FUNC_QUALIFIER tvec4 isinf(tquat const& q) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isinf' only accept floating-point inputs"); + + return tvec4(isinf(q.x), isinf(q.y), isinf(q.z), isinf(q.w)); + } }//namespace glm #if GLM_ARCH != GLM_ARCH_PURE && GLM_HAS_UNRESTRICTED_UNIONS diff --git a/readme.md b/readme.md index f5040ce8..8693cb08 100644 --- a/readme.md +++ b/readme.md @@ -66,6 +66,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Added 'aligned' qualifiers - Added GTC_type_aligned with aligned *vec* types - Added GTC_functions extension +- Added quaternion version of isnan and isinf #521 ##### Improvements: - Improved SIMD and swizzle operators interactions with GCC and Clang #474 diff --git a/test/core/core_func_common.cpp b/test/core/core_func_common.cpp index 80b7c01c..533c1ff9 100644 --- a/test/core/core_func_common.cpp +++ b/test/core/core_func_common.cpp @@ -1212,7 +1212,7 @@ int main() glm::int32 const c(1); glm::int32 const d = ~c; -# if GLM_ARCH & GLM_ARCH_AVX_BIT +# if GLM_ARCH & GLM_ARCH_AVX_BIT && GLM_HAS_UNRESTRICTED_UNIONS glm_vec4 const A = _mm_set_ps(4, 3, 2, 1); glm_vec4 const B = glm_vec4_swizzle_xyzw(A); glm_vec4 const C = _mm_permute_ps(A, _MM_SHUFFLE(3, 2, 1, 0));