| 77 | // avoid large relative differences for small numbers. |
| 78 | template<typename T> |
| 79 | inline bool EqualWithSafeRelError(T value, |
| 80 | T expected, |
| 81 | T eps, |
| 82 | T minExpected, |
| 83 | T* computedError = nullptr) |
| 84 | { |
| 85 | // If value and expected are infinity, return true. |
| 86 | if (value == expected) return true; |
| 87 | if (IsNan(value) && IsNan(expected)) return true; |
| 88 | const T div = (expected > 0) ? |
| 89 | ((expected < minExpected) ? minExpected : expected) : |
| 90 | ((-expected < minExpected) ? minExpected : -expected); |
| 91 | |
| 92 | T err = ((value > expected) ? value - expected : expected - value) / div; |
| 93 | |
| 94 | if (computedError) |
| 95 | { |
| 96 | *computedError = err; |
| 97 | } |
| 98 | |
| 99 | return (err <= eps); |
| 100 | } |
| 101 | |
| 102 | // C++20 introduces new strongly typed, UTF-8 based, char8_t and u8string types |
| 103 | // which are not implicitly convertible to char and std::string respectively. |
no test coverage detected