diff --git a/matrix/helper_functions.hpp b/matrix/helper_functions.hpp index 4ddeabf922..81e6243733 100644 --- a/matrix/helper_functions.hpp +++ b/matrix/helper_functions.hpp @@ -34,7 +34,9 @@ bool is_finite(Type x) { template bool isEqualF(const Type x, const Type y, const Type eps = 1e-4f) { - return matrix::fabs(x - y) <= eps; + return (matrix::fabs(x - y) <= eps) + || (isnan(x) && isnan(y)) + || (isinf(x) && isinf(y)); } /** diff --git a/test/helper.cpp b/test/helper.cpp index 7dd1fb94b8..4bd13daaec 100644 --- a/test/helper.cpp +++ b/test/helper.cpp @@ -46,8 +46,9 @@ int main() TEST(!isEqualF(1.f, NAN)); TEST(!isEqualF(INFINITY, 1.f)); TEST(!isEqualF(1.f, INFINITY)); - TEST(!isEqualF(NAN, NAN)); - TEST(!isEqualF(INFINITY, INFINITY)); + TEST(isEqualF(NAN, NAN)); + TEST(isEqualF(NAN, -NAN)); + TEST(isEqualF(INFINITY, INFINITY)); Vector3f a(1, 2, 3); Vector3f b(4, 5, 6); @@ -58,7 +59,7 @@ int main() Vector3f d(1, 2, NAN); TEST(!isEqual(c, d)); TEST(isEqual(c, c)); - TEST(!isEqual(d, d)); + TEST(isEqual(d, d)); return 0; }