Fixed error: comparing floating point with == or != is unsafe

This commit is contained in:
Groove 2018-07-28 21:18:15 +02:00
parent 21d030ad3d
commit 3e364981e8
3 changed files with 8 additions and 7 deletions

View File

@ -18,6 +18,7 @@
#include "../mat4x4.hpp"
#include "../vec3.hpp"
#include "../vec4.hpp"
#include "../ext/vector_relational.hpp"
#include "../gtc/constants.hpp"
#include "../gtc/matrix_transform.hpp"

View File

@ -603,10 +603,10 @@ namespace detail
GLM_FUNC_QUALIFIER T pitch(tquat<T, Q> const& q)
{
//return T(atan(T(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
const T y = static_cast<T>(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;
T const y = static_cast<T>(2) * (q.y * q.z + q.w * q.x);
T const x = q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z;
if(detail::compute_equal<T, std::numeric_limits<T>::is_iec559>::call(y, static_cast<T>(0)) && detail::compute_equal<T, std::numeric_limits<T>::is_iec559>::call(x, static_cast<T>(0))) //avoid atan2(0,0) - handle singularity - Matiis
if(all(equal(vec<2, T, Q>(x, y), vec<2, T, Q>(0), epsilon<T>()))) //avoid atan2(0,0) - handle singularity - Matiis
return static_cast<T>(static_cast<T>(2) * atan(q.x, q.w));
return static_cast<T>(atan(y, x));

View File

@ -10,8 +10,8 @@ static int test_vec1_operators()
{
int Error(0);
glm::ivec1 A(1.0f);
glm::ivec1 B(1.0f);
glm::ivec1 A(1);
glm::ivec1 B(1);
{
bool R = A != B;
bool S = A == B;