| 11074 | |
| 11075 | template <typename FP> |
| 11076 | bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) { |
| 11077 | // Comparison with NaN should always be false. |
| 11078 | // This way we can rule it out before getting into the ugly details |
| 11079 | if (Catch::isnan(lhs) || Catch::isnan(rhs)) { |
| 11080 | return false; |
| 11081 | } |
| 11082 | |
| 11083 | auto lc = convert(lhs); |
| 11084 | auto rc = convert(rhs); |
| 11085 | |
| 11086 | if ((lc.i < 0) != (rc.i < 0)) { |
| 11087 | // Potentially we can have +0 and -0 |
| 11088 | return lhs == rhs; |
| 11089 | } |
| 11090 | |
| 11091 | auto ulpDiff = std::abs(lc.i - rc.i); |
| 11092 | return ulpDiff <= maxUlpDiff; |
| 11093 | } |
| 11094 | |
| 11095 | template <typename FP> |
| 11096 | FP step(FP start, FP direction, int steps) { |