From ed90954ded72892c71e3b9a185de3f94956dc71c Mon Sep 17 00:00:00 2001 From: Rinzii Date: Mon, 1 Apr 2024 00:11:22 -0400 Subject: [PATCH] Patch ccm::nan in a manner that should make msvc happy --- .../ccmath/math/basic/impl/nan_double_impl.hpp | 4 +++- .../ccmath/math/basic/impl/nan_float_impl.hpp | 5 +++-- test/basic/nan_test.cpp | 18 ++++++------------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/include/ccmath/math/basic/impl/nan_double_impl.hpp b/include/ccmath/math/basic/impl/nan_double_impl.hpp index 95cf552..cb45544 100644 --- a/include/ccmath/math/basic/impl/nan_double_impl.hpp +++ b/include/ccmath/math/basic/impl/nan_double_impl.hpp @@ -74,7 +74,9 @@ namespace ccm::internal // NOLINTEND // Set the tag bits for NaN - dbl_bits |= UINT64_C(0x7FF8000000000000); + //dbl_bits |= UINT64_C(0x7FF8000000000000); + dbl_bits |= ccm::helpers::bit_cast(std::numeric_limits::quiet_NaN()); + // Convert the uint64_t tag into a double NaN return ccm::helpers::bit_cast(dbl_bits); diff --git a/include/ccmath/math/basic/impl/nan_float_impl.hpp b/include/ccmath/math/basic/impl/nan_float_impl.hpp index 8adcfeb..e70f07b 100644 --- a/include/ccmath/math/basic/impl/nan_float_impl.hpp +++ b/include/ccmath/math/basic/impl/nan_float_impl.hpp @@ -75,9 +75,10 @@ namespace ccm::internal // NOLINTEND // Set the tag bits for NaN - flt_bits |= UINT32_C(0x7F800000); + //flt_bits |= UINT32_C(0x7F800000); + flt_bits |= ccm::helpers::bit_cast(std::numeric_limits::quiet_NaN()); - // Convert the uint32_t bits to a float + // Convert the bits to a float return ccm::helpers::bit_cast(flt_bits); } } // namespace impl diff --git a/test/basic/nan_test.cpp b/test/basic/nan_test.cpp index 95f1751..1bcf632 100644 --- a/test/basic/nan_test.cpp +++ b/test/basic/nan_test.cpp @@ -29,16 +29,10 @@ TEST(CcmathBasicTests, NanStaticAssert) TEST(CcmathBasicTests, NanDouble) { - // TODO: Investigate why MSVC is adding 1 to the value of the nan bits of tests using this variable. -#if defined(_MSC_VER) - const std::uint64_t addPlusOneForMsvc = 1; -#else - const std::uint64_t addPlusOneForMsvc = 0; -#endif // Check the outcome if we are handling an empty string - std::uint64_t ccmNanBits = ccm::helpers::bit_cast(ccm::nan("")) + addPlusOneForMsvc; - std::uint64_t stdNanBits = ccm::helpers::bit_cast(std::nan("")) + addPlusOneForMsvc; + std::uint64_t ccmNanBits = ccm::helpers::bit_cast(ccm::nan("")); + std::uint64_t stdNanBits = ccm::helpers::bit_cast(std::nan("")); EXPECT_EQ(ccmNanBits, stdNanBits); // Check the outcome if we are handling a string with a single character that represents a number @@ -57,13 +51,13 @@ TEST(CcmathBasicTests, NanDouble) EXPECT_EQ(ccmNanBits, stdNanBits); // Check the outcome if we are handling a string with multiple characters with both numbers and characters with no hex prefix - ccmNanBits = ccm::helpers::bit_cast(ccm::nan("foo123bar")) + addPlusOneForMsvc; - stdNanBits = ccm::helpers::bit_cast(std::nan("foo123bar")) + addPlusOneForMsvc; + ccmNanBits = ccm::helpers::bit_cast(ccm::nan("foo123bar")); + stdNanBits = ccm::helpers::bit_cast(std::nan("foo123bar")); EXPECT_EQ(ccmNanBits, stdNanBits); // Check the outcome if we are handling a string with a hex prefix and a single character - ccmNanBits = ccm::helpers::bit_cast(ccm::nan("0x1")) + addPlusOneForMsvc; - stdNanBits = ccm::helpers::bit_cast(std::nan("0x1") + addPlusOneForMsvc); + ccmNanBits = ccm::helpers::bit_cast(ccm::nan("0x1")); + stdNanBits = ccm::helpers::bit_cast(std::nan("0x1")); EXPECT_EQ(ccmNanBits, stdNanBits); // Check for multi-digit wrapping