MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / almostEqualUlps

Function almostEqualUlps

unittests/catch.hpp:7935–7952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7933
7934template <typename FP>
7935bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) {
7936 // Comparison with NaN should always be false.
7937 // This way we can rule it out before getting into the ugly details
7938 if (std::isnan(lhs) || std::isnan(rhs)) {
7939 return false;
7940 }
7941
7942 auto lc = convert(lhs);
7943 auto rc = convert(rhs);
7944
7945 if ((lc.i < 0) != (rc.i < 0)) {
7946 // Potentially we can have +0 and -0
7947 return lhs == rhs;
7948 }
7949
7950 auto ulpDiff = std::abs(lc.i - rc.i);
7951 return ulpDiff <= maxUlpDiff;
7952}
7953
7954}
7955

Callers

nothing calls this directly

Calls 1

convertFunction · 0.85

Tested by

no test coverage detected