Skip to content

Commit c968f12

Browse files
committed
Math: Code cleaning
1 parent 89814eb commit c968f12

2 files changed

Lines changed: 6 additions & 18 deletions

File tree

modules/Math/Utility.mpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export module CppUtils.Math.Utility;
22

33
import std;
4+
import CppUtils.Type.Concept;
45

56
export namespace CppUtils::Math
67
{
@@ -26,24 +27,8 @@ export namespace CppUtils::Math
2627
static_assert(absolute(0u) == 0u);
2728
static_assert(absolute(1u) == 1u);
2829

29-
template<std::floating_point Float>
30-
[[nodiscard]] inline constexpr auto isEqual(Float lhs, Float rhs, Float epsilon = std::numeric_limits<Float>::epsilon()) noexcept -> bool
31-
{
32-
auto difference = absolute(lhs - rhs);
33-
auto maximum = std::max(absolute(lhs), absolute(rhs));
34-
if (maximum >= Float{1})
35-
return difference <= epsilon * maximum;
36-
else if (maximum > Float{0})
37-
return difference / maximum <= epsilon;
38-
return true;
39-
}
40-
41-
static_assert(isEqual(0.0, 0.0));
42-
static_assert(isEqual(0.1 + 0.2, 0.3));
43-
static_assert(not isEqual(0.1 + 0.2, 0.29));
44-
static_assert(not isEqual(0.1 + 0.2, 0.31));
45-
46-
[[nodiscard]] inline constexpr auto isBetween(auto value, auto low, auto high) noexcept -> bool
30+
template<Type::Numeric T>
31+
[[nodiscard]] inline constexpr auto isBetween(T value, T low, T high) noexcept -> bool
4732
{
4833
return low <= value and value <= high;
4934
}

modules/Type/Concept.mpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,7 @@ export namespace CppUtils::Type
6666

6767
template<class Function, class... Args>
6868
concept NotCallable = not Callable<Function, Args...>;
69+
70+
template<class T>
71+
concept Numeric = std::integral<T> or std::floating_point<T>;
6972
}

0 commit comments

Comments
 (0)