From 01f9ab5b6d21e5062ac0f6e0f205c7fa2ca9d769 Mon Sep 17 00:00:00 2001 From: Groove Date: Wed, 25 Jul 2018 00:40:39 +0200 Subject: [PATCH] Revert "- Fixed unexpected operator== behavior #723" This reverts commit c46981b4c336d5dbb0e2c2756247d8779805bcfb. --- glm/detail/compute_vector_relational.hpp | 17 +++++++++++++++++ glm/detail/func_vector_relational.inl | 4 ++-- glm/detail/type_vec1.inl | 2 +- glm/detail/type_vec2.inl | 4 +++- glm/detail/type_vec3.inl | 5 ++++- glm/detail/type_vec4.inl | 6 +++++- glm/gtc/packing.inl | 2 +- glm/gtc/quaternion.inl | 6 +++--- glm/gtc/ulp.inl | 12 ++++++------ glm/gtx/scalar_relational.inl | 4 ++-- readme.md | 1 - 11 files changed, 44 insertions(+), 19 deletions(-) diff --git a/glm/detail/compute_vector_relational.hpp b/glm/detail/compute_vector_relational.hpp index e1cf3490..20637a3c 100644 --- a/glm/detail/compute_vector_relational.hpp +++ b/glm/detail/compute_vector_relational.hpp @@ -7,6 +7,23 @@ namespace glm{ namespace detail { + template + struct compute_equal + { + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T a, T b) + { + return a == b; + } + }; + template + struct compute_equal + { + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T a, T b) + { + return detail::compute_abs::is_signed>::call(b - a) <= static_cast(0); + //return std::memcmp(&a, &b, sizeof(T)) == 0; + } + }; }//namespace detail }//namespace glm diff --git a/glm/detail/func_vector_relational.inl b/glm/detail/func_vector_relational.inl index 85014396..1b256eda 100644 --- a/glm/detail/func_vector_relational.inl +++ b/glm/detail/func_vector_relational.inl @@ -64,7 +64,7 @@ namespace glm vec Result GLM_BUG_VC_INIT; for(length_t i = 0; i < x.length(); ++i) - Result[i] = x[i] == y[i]; + Result[i] = detail::compute_equal::is_iec559>::call(x[i], y[i]); return Result; } @@ -75,7 +75,7 @@ namespace glm vec Result GLM_BUG_VC_INIT; for(length_t i = 0; i < x.length(); ++i) - Result[i] = x[i] != y[i]; + Result[i] = !detail::compute_equal::is_iec559>::call(x[i], y[i]); return Result; } diff --git a/glm/detail/type_vec1.inl b/glm/detail/type_vec1.inl index dcb229bf..9f971501 100644 --- a/glm/detail/type_vec1.inl +++ b/glm/detail/type_vec1.inl @@ -529,7 +529,7 @@ namespace glm template GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool operator==(vec<1, T, Q> const& v1, vec<1, T, Q> const& v2) { - return v1.x == v2.x; + return detail::compute_equal::is_iec559>::call(v1.x, v2.x); } template diff --git a/glm/detail/type_vec2.inl b/glm/detail/type_vec2.inl index 8f924d79..d1727a3e 100644 --- a/glm/detail/type_vec2.inl +++ b/glm/detail/type_vec2.inl @@ -875,7 +875,9 @@ namespace glm template GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool operator==(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2) { - return v1.x == v2.x && v1.y == v2.y; + return + detail::compute_equal::is_iec559>::call(v1.x, v2.x) && + detail::compute_equal::is_iec559>::call(v1.y, v2.y); } template diff --git a/glm/detail/type_vec3.inl b/glm/detail/type_vec3.inl index 6bfb03fc..ca9707a9 100644 --- a/glm/detail/type_vec3.inl +++ b/glm/detail/type_vec3.inl @@ -1023,7 +1023,10 @@ namespace glm template GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool operator==(vec<3, T, Q> const& v1, vec<3, T, Q> const& v2) { - return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z; + return + detail::compute_equal::is_iec559>::call(v1.x, v2.x) && + detail::compute_equal::is_iec559>::call(v1.y, v2.y) && + detail::compute_equal::is_iec559>::call(v1.z, v2.z); } template diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 0055a45b..2565d547 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -129,7 +129,11 @@ namespace detail { GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2) { - return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w; + return + detail::compute_equal::is_iec559>::call(v1.x, v2.x) && + detail::compute_equal::is_iec559>::call(v1.y, v2.y) && + detail::compute_equal::is_iec559>::call(v1.z, v2.z) && + detail::compute_equal::is_iec559>::call(v1.w, v2.w); } }; diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 3105679f..eebdc1de 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -620,7 +620,7 @@ namespace detail float const ExpSharedP = max(-15.f - 1.f, floor(log2(MaxColor))) + 1.0f + 15.f; float const MaxShared = floor(MaxColor / pow(2.0f, (ExpSharedP - 15.f - 9.f)) + 0.5f); - float const ExpShared = MaxShared == pow(2.0f, 9.0f) ? ExpSharedP + 1.0f : ExpSharedP; + float const ExpShared = detail::compute_equal::is_iec559>::call(MaxShared, pow(2.0f, 9.0f)) ? ExpSharedP + 1.0f : ExpSharedP; uvec3 const ColorComp(floor(Color / pow(2.f, (ExpShared - 15.f - 9.f)) + 0.5f)); diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 255744e3..0ea87f09 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -600,7 +600,7 @@ namespace detail const T y = static_cast(2) * (q.y * q.z + q.w * q.x); const T x = q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z; - if(y == static_cast(0) && x == static_cast(0)) //avoid atan2(0,0) - handle singularity - Matiis + if(detail::compute_equal::is_iec559>::call(y, static_cast(0)) && detail::compute_equal::is_iec559>::call(x, static_cast(0))) //avoid atan2(0,0) - handle singularity - Matiis return static_cast(static_cast(2) * atan(q.x,q.w)); return static_cast(atan(y,x)); @@ -769,7 +769,7 @@ namespace detail { vec<4, bool, Q> Result; for(length_t i = 0; i < x.length(); ++i) - Result[i] = x[i] == y[i]; + Result[i] = detail::compute_equal::is_iec559>::call(x[i], y[i]); return Result; } @@ -778,7 +778,7 @@ namespace detail { vec<4, bool, Q> Result; for(length_t i = 0; i < x.length(); ++i) - Result[i] = x[i] != y[i]; + Result[i] = !detail::compute_equal::is_iec559>::call(x[i], y[i]); return Result; } diff --git a/glm/gtc/ulp.inl b/glm/gtc/ulp.inl index b1954c7f..ed018d5e 100644 --- a/glm/gtc/ulp.inl +++ b/glm/gtc/ulp.inl @@ -82,13 +82,13 @@ namespace detail if((ix>0x7f800000) || // x is nan (iy>0x7f800000)) // y is nan return x+y; - if(x == y) + if(compute_equal::is_iec559>::call(x, y)) return y; // x=y, return y if(ix==0) { // x == 0 GLM_SET_FLOAT_WORD(x,(hy&0x80000000)|1);// return +-minsubnormal t = x*x; - if(abs(t - x) <= 0.0f) + if(detail::compute_equal::call(t, x)) return t; else return x; // raise underflow flag @@ -113,7 +113,7 @@ namespace detail if(hy<0x00800000) // underflow { t = x*x; - if(abs(t - x) > 0.0f) + if(!detail::compute_equal::call(t, x)) { // raise underflow flag GLM_SET_FLOAT_WORD(y,hx); return y; @@ -137,13 +137,13 @@ namespace detail if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || // x is nan ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) // y is nan return x+y; - if(x == y) + if(detail::compute_equal::call(x, y)) return y; // x=y, return y if((ix|lx)==0) { // x == 0 GLM_INSERT_WORDS(x, hy & 0x80000000, 1); // return +-minsubnormal t = x*x; - if(abs(t - x) <= 0.0) + if(detail::compute_equal::call(t, x)) return t; else return x; // raise underflow flag @@ -171,7 +171,7 @@ namespace detail if(hy<0x00100000) { // underflow t = x*x; - if(abs(t - x) > 0.0) + if(!detail::compute_equal::call(t, x)) { // raise underflow flag GLM_INSERT_WORDS(y,hx,lx); return y; diff --git a/glm/gtx/scalar_relational.inl b/glm/gtx/scalar_relational.inl index c6b26c2d..c616e07e 100644 --- a/glm/gtx/scalar_relational.inl +++ b/glm/gtx/scalar_relational.inl @@ -50,7 +50,7 @@ namespace glm T const& y ) { - return x == y; + return detail::compute_equal::is_iec559>::call(x, y); } template @@ -60,7 +60,7 @@ namespace glm T const& y ) { - return x != y; + return !detail::compute_equal::is_iec559>::call(x, y); } GLM_FUNC_QUALIFIER bool any diff --git a/readme.md b/readme.md index 3be5887a..c338aa56 100644 --- a/readme.md +++ b/readme.md @@ -69,7 +69,6 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate) - Fixed ortho #790 - Fixed Visual C++ 2013 warnings in vector relational code #782 - Fixed ICC build errors with constexpr #704 -- Fixed unexpected operator== behavior #723 ### [GLM 0.9.9.0](https://github.com/g-truc/glm/releases/tag/0.9.9.0) - 2018-05-22 #### Features: