25#ifndef JAU_BASE_MATH_HPP_
26#define JAU_BASE_MATH_HPP_
61 template<jau::req::arithmetic T>
62 bool in_range(
const T& a,
const T& b,
const T& range) {
63 return std::abs(a-b) <= range;
74 requires std::floating_point<T>
100 template <jau::req::
signed_arithmetic T>
101 constexpr int sign(
const T x)
noexcept
103 return (
int) ( (T(0) < x) - (x < T(0)) );
106 template <jau::req::
unsigned_arithmetic T>
107 constexpr int sign(
const T x)
noexcept
109 return (
int) ( T(0) < x );
138 template <jau::req::
signed_arithmetic T>
141 return std::numeric_limits<T>::min() == x ? std::numeric_limits<T>::max() : -x;
144 template <jau::req::
unsigned_arithmetic T>
163 template <jau::req::
signed_arithmetic T>
164 constexpr T
abs(
const T x)
noexcept
169 template <jau::req::
unsigned_arithmetic T>
170 constexpr T
abs(
const T x)
noexcept
182 template <jau::req::arithmetic T>
183 constexpr T
min(
const T x,
const T y)
noexcept
185 return x < y ? x : y;
195 template <jau::req::arithmetic T>
196 constexpr T
max(
const T x,
const T y)
noexcept
198 return x > y ? x : y;
211 template <jau::req::arithmetic T>
212 constexpr T
clamp(
const T x,
const T min_val,
const T max_val)
noexcept
Concept of type-trait std::is_signed and std::is_integral.
Concept of type-trait std::is_unsigned and std::is_integral.
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 bool is_positive(const T a) noexcept
Returns true of the given integral is positive, i.e.
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.