Skip to content

Commit

Permalink
refactor constant
Browse files Browse the repository at this point in the history
  • Loading branch information
schuhmaj committed May 8, 2024
1 parent 675a1e4 commit 6912693
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/util/UtilityFloatArithmeticTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "polyhedralGravity/util/UtilityFloatArithmetic.h"

/** Contains the positive infinity values for doubles */
constexpr static double INF = std::numeric_limits<double>::infinity();

TEST(UtilityFloatArithmeticTest, TestAlmostEqualUlps) {
// Checking the signess && identity
Expand All @@ -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<double>::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));

Expand Down Expand Up @@ -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<double>::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));
}

0 comments on commit 6912693

Please sign in to comment.