22 template <std::
integral T>
constexpr T
is_infinite(T)
noexcept {
return false; }
23 template <std::
integral T>
constexpr T
is_nan(T)
noexcept {
return false; }
31 template <std::
floating_po
int T>
constexpr T
copysign(T to, T from)
noexcept
34 return nem::intr::_nem_copysign(to, from);
36 template <nem::scalar_type T>
constexpr T
sign(T value)
noexcept {
return nem::copysign<T>((T)1.0, value); }
38 template <
typename T>
constexpr T
abs(T value)
noexcept {
return T{ value >= 0 ? value : -value }; }
39 template <std::
floating_po
int T>
constexpr T
abs(T value)
noexcept {
return nem::intr::_nem_fabs(value); }
49 template <std::
integral T>
constexpr bool is_zero(T a)
noexcept {
return a == 0; }
51 template <nem::scalar_type T>
constexpr bool is_zero_or_neg(T a)
noexcept {
return a <= eps<T>(); }
56 template <nem::scalar_type T>
constexpr bool equal(T a, T b)
noexcept {
return nem::is_zero(a - b); }
58 template <nem::scalar_type T>
constexpr T
get_max(T a, T b)
noexcept {
return (a > b) ? a : b; }
60 template <nem::scalar_type T>
constexpr T
get_min(T a, T b)
noexcept {
return (a < b) ? a : b; }
62 template <nem::scalar_type T>
constexpr T
average(T a, T b)
noexcept {
return (a + b) / (T)2.0; }
69 template <
typename T>
constexpr T
pow2(T value)
noexcept {
return T{ value * value }; }
70 template <
typename T>
constexpr T
pow3(T value)
noexcept {
return T{ value * value * value }; }
71 template <
typename T>
constexpr T
pow4(T value)
noexcept {
return T{ value * value * value * value }; }
72 template <
typename T>
constexpr T
sqr (T value)
noexcept {
return T{ value * value }; }
73 template <
typename T>
constexpr T
cube(T value)
noexcept {
return T{ value * value * value }; }
79 template <nem::scalar_type T>
constexpr T
truncate(T value)
noexcept
81 return (T)(
long long int)value;
87 template <nem::scalar_type T>
constexpr T
floor(T value)
noexcept
90 return trunc - (trunc > value);
101 template <nem::scalar_type T>
constexpr T
ceil(T value)
noexcept
104 return floored + (floored < value);
115 template <nem::scalar_type T>
constexpr T
mod(T a, T b)
123 const T r = v < 0 ? v + absb : v;
133 template <std::
floating_po
int T>
constexpr T
frac(T value)
noexcept
144 template <std::
floating_po
int T>
constexpr T
round(T value)
noexcept
147 const T ceiled = floored + (floored < value);
148 const T neg_dist = value - floored;
149 const T pos_dist = ceiled - value;
150 const bool up = pos_dist < (neg_dist + nem::eps<T>());
151 return ceiled * up + floored * !up;
165 template <std::
floating_po
int T>
constexpr T
floor(T value, T step)
177 template <std::
integral T>
constexpr T
floor(T value, T step)
noexcept
189 template <std::
floating_po
int T>
constexpr T
ceil(T value, T step)
201 template <std::
integral T>
constexpr T
ceil(T value, T step)
213 template <std::
floating_po
int T>
constexpr T
round(T value, T step)
225 template <std::
integral T>
constexpr T
round(T value, T step)
237 template <nem::scalar_type T>
constexpr T
repeat(T value, T lengthExcl)
245 template <nem::scalar_type T>
constexpr T
repeat(T value, T minIncl, T maxExcl)
247 return minIncl +
nem::mod(value - minIncl, maxExcl - minIncl);
256 template <nem::scalar_type T>
constexpr T
pingpong(T value, T minIncl, T maxExcl)
258 return minIncl +
nem::pingpong(value - minIncl, maxExcl - minIncl);
261 template <std::totally_ordered T>
constexpr T
clamp(T value, T minIncl, T maxIncl)
noexcept
263 if (value > maxIncl)
return maxIncl;
264 else if (value < minIncl)
return minIncl;
267 template <std::totally_ordered T>
constexpr T
clamp01(T value)
noexcept
276 template <
typename T>
constexpr T
smoothstep(T edge0, T edge1, T x)
278 const T
length = edge1 - edge0;
283 x =
nem::clamp((x - edge0) / (edge1 - edge0), (T)0.0, (T)1.0);
284 return x * x * ((T)3.0 - (T)2.0 * x);
286 template <
typename T>
constexpr T
lerp(T a, T b, T t) {
return b * t + a * ((T)1.0 - t); }
292 template <nem::scalar_type T>
constexpr T
remap(T value, T fromMin, T fromMax, T toMin, T toMax)
294 const T fromLength = fromMax - fromMin;
299 return toMin + (toMax - toMin) * ((value - fromMin) / fromLength);
307 template <std::
floating_po
int T>
constexpr T
is_whole(T value)
313 template <std::
integral T>
constexpr T
is_whole(T value)
T invalid_result(nem::error::Kind kind=Kind::RuntimeError, const char *const msg=nullptr)
bool _nem_isfinite(T x) noexcept
constexpr T smoothstep(T edge0, T edge1, T x)
constexpr T floor(T value) noexcept
Floors always towards -infinity.
constexpr T get_max(T a, T b) noexcept
constexpr T get_min(T a, T b) noexcept
constexpr T mod(T a, T b)
Calculates euclidean modulo of a % b = r, where r belongs to [0, b). Unline standard C++ modulo opera...
constexpr T ceil(T value) noexcept
Ceils always towards +infinity.
constexpr T repeat(T value, T lengthExcl)
Unwinds number to 0 when goes past length. Lengh is excluded: when value == lengthExcl,...
constexpr T remap(T value, T fromMin, T fromMax, T toMin, T toMax)
constexpr T is_nan(T value) noexcept
constexpr T sign(T value) noexcept
constexpr T abs(T value) noexcept
constexpr bool is_zero(T a) noexcept
Is a nearly 0? Given an Epsilon > 0, within each all numbers are considered indistinguisable from 0,...
constexpr T pow3(T value) noexcept
constexpr T pow4(T value) noexcept
constexpr bool is_zero_or_neg(T a) noexcept
constexpr T frac(T value) noexcept
Returns the fractional part of the floating-point number, with respect to sign 3.5 -> 0....
constexpr T pow2(T value) noexcept
constexpr T round(T value) noexcept
constexpr T pingpong(T value, T length)
constexpr T is_infinite(T value) noexcept
constexpr T copysign(T to, T from) noexcept
Copies the sign of {from} over to {to}. If the signs were the same, it doesn't change.
constexpr T clamp01(T value) noexcept
constexpr T truncate(T value) noexcept
constexpr T sqr(T value) noexcept
constexpr bool equal(T a, T b) noexcept
Are a and b nearly equal? Given an Epsilon > 0, within each all numbers are considered indistinguisab...
T length(const nem::quat_t< T > &q)
constexpr T lerp(T a, T b, T t)
constexpr T clamp(T value, T minIncl, T maxIncl) noexcept
constexpr T cube(T value) noexcept
constexpr T is_whole(T value)
Is a floating point number whole (same as integer)
constexpr T average(T a, T b) noexcept