25#ifndef JAU_BASE_MATH_HPP_
26#define JAU_BASE_MATH_HPP_
60 template<jau::req::arithmetic T>
61 bool in_range(
const T& a,
const T& b,
const T& range) {
62 return std::abs(a-b) <= range;
80 template <jau::req::
signed_arithmetic T>
81 constexpr int sign(
const T x)
noexcept
83 return (
int) ( (T(0) < x) - (x < T(0)) );
86 template <jau::req::
unsigned_arithmetic T>
87 constexpr int sign(
const T x)
noexcept
89 return (
int) ( T(0) < x );
118 template <jau::req::
signed_arithmetic T>
121 return std::numeric_limits<T>::min() == x ? std::numeric_limits<T>::max() : -x;
124 template <jau::req::
unsigned_arithmetic T>
143 template <jau::req::
signed_arithmetic T>
144 constexpr T
abs(
const T x)
noexcept
149 template <jau::req::
unsigned_arithmetic T>
150 constexpr T
abs(
const T x)
noexcept
162 template <jau::req::arithmetic T>
163 constexpr T
min(
const T x,
const T y)
noexcept
165 return x < y ? x : y;
175 template <jau::req::arithmetic T>
176 constexpr T
max(
const T x,
const T y)
noexcept
178 return x > y ? x : y;
191 template <jau::req::arithmetic T>
192 constexpr T
clamp(
const T x,
const T min_val,
const T max_val)
noexcept
constexpr T invert_sign(const T x) noexcept
Safely inverts the sign of an arithmetic number w/ branching in O(1)
constexpr T clamp(const T x, const T min_val, const T max_val) noexcept
Returns constrained integral value to lie between given min- and maximum value (w/ branching) in O(1)...
constexpr int sign(const T x) noexcept
Returns the value of the sign function (w/o branching ?) in O(1).
constexpr T min(const T x, const T y) noexcept
Returns the minimum of two integrals (w/ branching) in O(1)
bool in_range(const T &a, const T &b, const T &range)
base_math: arithmetic types, i.e.
constexpr T max(const T x, const T y) noexcept
Returns the maximum of two integrals (w/ branching) in O(1)
constexpr T abs(const T x) noexcept
Returns the absolute value of an arithmetic number (w/ branching) in O(1)
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.