| 9356 | |
| 9357 | template <typename FP> |
| 9358 | bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) { |
| 9359 | // Comparison with NaN should always be false. |
| 9360 | // This way we can rule it out before getting into the ugly details |
| 9361 | if (Catch::isnan(lhs) || Catch::isnan(rhs)) { |
| 9362 | return false; |
| 9363 | } |
| 9364 | |
| 9365 | auto lc = convert(lhs); |
| 9366 | auto rc = convert(rhs); |
| 9367 | |
| 9368 | if ((lc.i < 0) != (rc.i < 0)) { |
| 9369 | // Potentially we can have +0 and -0 |
| 9370 | return lhs == rhs; |
| 9371 | } |
| 9372 | |
| 9373 | auto ulpDiff = std::abs(lc.i - rc.i); |
| 9374 | return ulpDiff <= maxUlpDiff; |
| 9375 | } |
| 9376 | |
| 9377 | } |
| 9378 | |