mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-13 04:06:52 +07:00
fix approx<unsigned> with epsilon
This commit is contained in:
@@ -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 >
|
||||
|
||||
@@ -154,6 +154,13 @@ TEST_CASE("vmath/fun") {
|
||||
STATIC_CHECK_FALSE(approx(1, 3, 1));
|
||||
STATIC_CHECK(approx(1, 3, 2));
|
||||
|
||||
STATIC_CHECK(approx(1u, 1u));
|
||||
STATIC_CHECK_FALSE(approx(0u, 1u));
|
||||
STATIC_CHECK_FALSE(approx(0u, 1u, 0u));
|
||||
STATIC_CHECK(approx(0u, 1u, 1u));
|
||||
STATIC_CHECK_FALSE(approx(1u, 3u, 1u));
|
||||
STATIC_CHECK(approx(1u, 3u, 2u));
|
||||
|
||||
STATIC_CHECK(approx(1.f, 1.f));
|
||||
STATIC_CHECK_FALSE(approx(0.f, 1.f));
|
||||
STATIC_CHECK_FALSE(approx(0.f, 1.f, 0.f));
|
||||
|
||||
Reference in New Issue
Block a user