| 123456789101112131415161718192021222324252627282930313233343536373839 |
- #pragma once
- #include <algorithm>
- #include <cmath>
- namespace math {
- template <typename T>
- bool between(T val, T min, T max) {
- return val >= min && val < max;
- }
- template <typename T>
- bool approx_equal(T lhs, T rhs, T eps) {
- T const a = std::abs(lhs);
- T const b = std::abs(rhs);
- return std::abs(lhs - rhs) <= (std::max(a, b) * eps);
- }
-
- template <typename T>
- bool essentially_equal(T lhs, T rhs, T eps) {
- T const a = std::abs(lhs);
- T const b = std::abs(rhs);
- return std::abs(lhs - rhs) <= (std::min(a, b) * eps);
- }
-
- template <typename T>
- bool definitely_greater(T lhs, T rhs, T eps) {
- T const a = std::abs(lhs);
- T const b = std::abs(rhs);
- return (lhs - rhs) > (std::max(a, b) * eps);
- }
-
- template <typename T>
- bool definitely_less(T lhs, T rhs, T eps) {
- T const a = std::abs(lhs);
- T const b = std::abs(rhs);
- return (rhs - lhs) > (std::max(a, b) * eps);
- }
- }
|