13 #include "mathematics.h" 19 BEGIN_NAMESPACE_MATHEMATICS
35 static bool inRange(T input, T minimum, T maximum);
45 static T
ensureRange(T input, T minimum, T maximum);
55 static bool areSame(T first, T second, T epsilon = (T) std::numeric_limits<T>::epsilon());
64 static bool isZero(T input, T epsilon = (T) std::numeric_limits<T>::epsilon());
73 static T
gcd(T first, T second);
82 static T
lcm(T first, T second);
88 return (minimum <= input) && (input <= maximum);
94 assert(minimum <= maximum);
102 template <
typename T>
105 static_assert(std::is_arithmetic_v<T>,
"areSame type not supported.");
107 if constexpr (std::is_integral<T>::value)
109 if constexpr (!std::is_unsigned<T>::value)
122 return max - min <= epsilon;
124 return std::fabs(first - second) <= std::fabs(epsilon);
130 return areSame(input, T(0), epsilon);
136 return std::gcd(first, second);
142 return std::lcm(first, second);
145 END_NAMESPACE_MATHEMATICS
static T lcm(T first, T second)
Function returns lowest common multiple for for two values.
Definition: mathfuncs.h:140
static T gcd(T first, T second)
Function returns greatest common divisor for two values.
Definition: mathfuncs.h:134
static bool inRange(T input, T minimum, T maximum)
Indicates whether a value falls within a specified range.
Definition: mathfuncs.h:86
static bool isZero(T input, T epsilon=(T) std::numeric_limits< T >::epsilon())
Function checks if value is zero.
Definition: mathfuncs.h:128
The class implements helper functions for mathematical operations.
Definition: mathfuncs.h:24
static T ensureRange(T input, T minimum, T maximum)
Function returns a value that is guaranteed to be within a specified range.
Definition: mathfuncs.h:92
static bool areSame(T first, T second, T epsilon=(T) std::numeric_limits< T >::epsilon())
Function checks if two values are the same within data types limitation.
Definition: mathfuncs.h:103