diff --git a/test/util/UtilityFloatArithmeticTest.cpp b/test/util/UtilityFloatArithmeticTest.cpp index 25853a7..cdf08e5 100644 --- a/test/util/UtilityFloatArithmeticTest.cpp +++ b/test/util/UtilityFloatArithmeticTest.cpp @@ -7,6 +7,8 @@ #include "polyhedralGravity/util/UtilityFloatArithmetic.h" +/** Contains the positive infinity values for doubles */ +constexpr static double INF = std::numeric_limits::infinity(); TEST(UtilityFloatArithmeticTest, TestAlmostEqualUlps) { // Checking the signess && identity @@ -33,9 +35,9 @@ TEST(UtilityFloatArithmeticTest, TestAlmostEqualUlps) { // Checking the the sensitivity towards the next floating point // Note: The default maximal ULPS distance is set to 4 // The ULP distance is one time higher than 4 leading to false, one time lower equal leading to true - const auto inf = std::numeric_limits::infinity(); - const double fourHops = std::nextafter(std::nextafter(std::nextafter(std::nextafter(3.0, inf), inf), inf), inf); - const double fiveHops = std::nextafter(std::nextafter(std::nextafter(std::nextafter(std::nextafter(3.0, inf), inf), inf), inf), inf); + // Can be constexpr starting with C++23 + const double fourHops = std::nextafter(std::nextafter(std::nextafter(std::nextafter(3.0, INF), INF), INF), INF); + const double fiveHops = std::nextafter(fourHops, INF); ASSERT_TRUE(polyhedralGravity::util::almostEqualUlps(3.0, fourHops)); ASSERT_FALSE(polyhedralGravity::util::almostEqualUlps(3.0, fiveHops)); @@ -67,9 +69,9 @@ TEST(UtilityFloatArithmeticTest, TestAlmostEqualRelative) { // Checking the the sensitivity towards the next floating point // A ULP distance of 4 or 5 is still really small than our relative sensitivity of 1e-10 - const auto inf = std::numeric_limits::infinity(); - const double fourHops = std::nextafter(std::nextafter(std::nextafter(std::nextafter(3.0, inf), inf), inf), inf); - const double fiveHops = std::nextafter(std::nextafter(std::nextafter(std::nextafter(std::nextafter(3.0, inf), inf), inf), inf), inf); + // Can be constexpr starting with C++23 + const double fourHops = std::nextafter(std::nextafter(std::nextafter(std::nextafter(3.0, INF), INF), INF), INF); + const double fiveHops = std::nextafter(fourHops, INF); ASSERT_TRUE(polyhedralGravity::util::almostEqualRelative(3.0, fourHops)); ASSERT_TRUE(polyhedralGravity::util::almostEqualRelative(3.0, fiveHops)); }