fix approx<unsigned> with epsilon

This commit is contained in:
BlackMATov
2021-02-28 13:13:50 +07:00
parent c1cb6cba78
commit 29755fe067
2 changed files with 12 additions and 1 deletions

View File

@@ -396,7 +396,11 @@ namespace vmath_hpp
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
constexpr approx(T x, T y, T epsilon) noexcept {
return abs(x - y) <= epsilon;
if constexpr ( std::is_unsigned_v<T> ) {
return (x < y ? (y - x) : (x - y)) <= epsilon;
} else {
return abs(x - y) <= epsilon;
}
}
template < typename T >