MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / almostEqualUlps

Function almostEqualUlps

extern/Catch2/catch.hpp:11501–11519  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11499
11500 template <typename FP>
11501 bool almostEqualUlps(FP lhs, FP rhs, uint64_t maxUlpDiff) {
11502 // Comparison with NaN should always be false.
11503 // This way we can rule it out before getting into the ugly details
11504 if (Catch::isnan(lhs) || Catch::isnan(rhs)) {
11505 return false;
11506 }
11507
11508 auto lc = convert(lhs);
11509 auto rc = convert(rhs);
11510
11511 if ((lc < 0) != (rc < 0)) {
11512 // Potentially we can have +0 and -0
11513 return lhs == rhs;
11514 }
11515
11516 // static cast as a workaround for IBM XLC
11517 auto ulpDiff = std::abs(static_cast<FP>(lc - rc));
11518 return static_cast<uint64_t>(ulpDiff) <= maxUlpDiff;
11519 }
11520
11521#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
11522

Callers

nothing calls this directly

Calls 3

isnanFunction · 0.85
convertFunction · 0.70
absFunction · 0.50

Tested by

no test coverage detected