From 1bfb954e43f6f051ca231dbe8ef62576e028d222 Mon Sep 17 00:00:00 2001 From: Achim Gsell <achim.gsell@psi.ch> Date: Fri, 9 Oct 2020 09:57:02 +0200 Subject: [PATCH] use std::isnan() in almost_eq() --- src/Structure/BoundaryGeometry.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Structure/BoundaryGeometry.cpp b/src/Structure/BoundaryGeometry.cpp index a91e82f97..a59864859 100644 --- a/src/Structure/BoundaryGeometry.cpp +++ b/src/Structure/BoundaryGeometry.cpp @@ -222,16 +222,17 @@ namespace cmp_ulp { See: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ */ - inline bool almost_eq(double A, double B, double maxDiff = 1e-20, int maxUlps = 1000) { + + + inline bool almost_eq (double A, double B, double maxDiff = 1e-20, int maxUlps = 1000) { // handle NaN's - // Note: comparing something with a NaN is always false! - if (A != A || B != B) { + if (std::isnan (A) || std::isnan (B)) { return false; } // Check if the numbers are really close -- needed // when comparing numbers near zero. - if (std::abs(A - B) <= maxDiff) + if (std::abs (A - B) <= maxDiff) return true; #pragma GCC diagnostic push @@ -242,15 +243,15 @@ namespace cmp_ulp { // Different signs means they do not match. // Note: a negative floating point number is also negative as integer. - if ( std::signbit(aInt) != std::signbit(bInt)) + if (std::signbit (aInt) != std::signbit (bInt)) return false; - + // Find the difference in ULPs. - return (std::abs(aInt - bInt) <= maxUlps); + return (std::abs (aInt - bInt) <= maxUlps); } inline bool almost_eq_zero(double A, double maxDiff = 1e-15) { - return (std::abs(A) <= maxDiff); + return (std::abs (A) <= maxDiff); } FUNC_EQ(x, y); FUNC_EQ_ZERO(x); -- GitLab