| 9130 | |
| 9131 | template <typename FP> |
| 9132 | bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) { |
| 9133 | // Comparison with NaN should always be false. |
| 9134 | // This way we can rule it out before getting into the ugly details |
| 9135 | if (Catch::isnan(lhs) || Catch::isnan(rhs)) { |
| 9136 | return false; |
| 9137 | } |
| 9138 | |
| 9139 | auto lc = convert(lhs); |
| 9140 | auto rc = convert(rhs); |
| 9141 | |
| 9142 | if ((lc.i < 0) != (rc.i < 0)) { |
| 9143 | // Potentially we can have +0 and -0 |
| 9144 | return lhs == rhs; |
| 9145 | } |
| 9146 | |
| 9147 | auto ulpDiff = std::abs(lc.i - rc.i); |
| 9148 | return ulpDiff <= maxUlpDiff; |
| 9149 | } |
| 9150 | |
| 9151 | } |
| 9152 | |