| 1312 | */ |
| 1313 | template<Concepts::Numeric T> |
| 1314 | [[nodiscard]] inline bool almostEqual(T a, T b, T relEps = T(1e-12), T absEps = T(1e-12)) noexcept |
| 1315 | { |
| 1316 | if constexpr (std::floating_point<T>) { |
| 1317 | if (!std::isfinite(a) || !std::isfinite(b)) |
| 1318 | return a == b; |
| 1319 | } |
| 1320 | |
| 1321 | const T diff = std::abs(a - b); |
| 1322 | |
| 1323 | if (diff <= absEps) |
| 1324 | return true; |
| 1325 | |
| 1326 | const T scale = std::max(std::abs(a), std::abs(b)); |
| 1327 | return diff <= relEps * scale; |
| 1328 | } |
| 1329 | |
| 1330 | /** |
| 1331 | * @brief Explicit "not equal" companion to almostEqual(). |
no test coverage detected