18#ifndef __FPSDK_COMMON_MATH_HPP__
19#define __FPSDK_COMMON_MATH_HPP__
51constexpr T
Clamp(
const T val,
const T min,
const T max)
53 return std::max(min, std::min(val, max));
67 static_assert(::std::is_floating_point<T>::value,
"Value must be float or double");
68 return degrees * M_PI / 180.0;
81 static_assert(::std::is_floating_point<T>::value,
"Value must be float or double");
82 return radians * 180.0 / M_PI;
128constexpr T
Bit(
const std::size_t bit)
130 return static_cast<T
>(
static_cast<uint64_t
>(1) << bit);
145 return (mask & bits) == bits;
160 return (mask & bits) != 0;
173constexpr T
GetBits(
const T value,
const T mask)
175 return (value & mask);
double RoundToFracDigits(const double value, const int digits)
Round to desired number of fractional digits (of precision)
double ClipToFracDigits(const double value, const int digits)
Clip to desired number of fractional digits (of precision)
constexpr T Clamp(const T val, const T min, const T max)
Clamp value in range.
constexpr T DegToRad(T degrees)
Convert degrees to radians.
constexpr T Bit(const std::size_t bit)
Return a number with the given bit set to 1 (i.e. 2^bit)
constexpr bool CheckBitsAny(const T mask, const T bits)
Checks if any bits are set.
void SetBits(T &mask, const T bits)
Sets the bits.
void ToggleBits(T &mask, const T bits)
Toggles the bits.
constexpr bool CheckBitsAll(const T mask, const T bits)
Checks if all bits are set.
constexpr T RadToDeg(T radians)
Convert radians to degrees.
void ClearBits(T &mask, const T bits)
Clears the bits.
constexpr T GetBits(const T value, const T mask)
Extracts bits.