diff --git a/modules/core/include/opencv2/core/fast_math.hpp b/modules/core/include/opencv2/core/fast_math.hpp index eb4fbe213b..47570f4cd2 100644 --- a/modules/core/include/opencv2/core/fast_math.hpp +++ b/modules/core/include/opencv2/core/fast_math.hpp @@ -295,7 +295,7 @@ CV_INLINE int cvIsInf( double value ) #elif defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__PPC64__) Cv64suf ieee754; ieee754.f = value; - return (ieee754.u & 0x7fffffff00000000) == + return (ieee754.u & 0x7fffffffffffffff) == 0x7ff0000000000000; #else Cv64suf ieee754; diff --git a/modules/core/test/test_math.cpp b/modules/core/test/test_math.cpp index cbd0b7ceb3..9baf285e96 100644 --- a/modules/core/test/test_math.cpp +++ b/modules/core/test/test_math.cpp @@ -3992,6 +3992,13 @@ TEST(Core_FastMath, InlineNaN) EXPECT_EQ( cvIsNaN((double) NAN), 1); EXPECT_EQ( cvIsNaN((double) -NAN), 1); EXPECT_EQ( cvIsNaN(0.0), 0); + + // Regression: check the +/-Inf cases + Cv64suf suf; + suf.u = 0x7FF0000000000000UL; + EXPECT_EQ( cvIsNaN(suf.f), 0); + suf.u = 0xFFF0000000000000UL; + EXPECT_EQ( cvIsNaN(suf.f), 0); } TEST(Core_FastMath, InlineIsInf) @@ -4003,6 +4010,13 @@ TEST(Core_FastMath, InlineIsInf) EXPECT_EQ( cvIsInf((double) HUGE_VAL), 1); EXPECT_EQ( cvIsInf((double) -HUGE_VAL), 1); EXPECT_EQ( cvIsInf(0.0), 0); + + // Regression: check the cases of 0x7FF00000xxxxxxxx + Cv64suf suf; + suf.u = 0x7FF0000000000001UL; + EXPECT_EQ( cvIsInf(suf.f), 0); + suf.u = 0x7FF0000012345678UL; + EXPECT_EQ( cvIsInf(suf.f), 0); } }} // namespace