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;
118constexpr T
Bit(
const size_t bit)
120 return static_cast<T
>(
static_cast<uint64_t
>(1) << bit);
135 return (mask & bits) == bits;
150 return (mask & bits) != 0;
163constexpr T
GetBits(
const T value,
const T mask)
165 return (value & mask);
double RoundToFracDigits(const double value, const int digits)
Round 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 bool CheckBitsAny(const T mask, const T bits)
Checks if any bits are set.
void SetBits(T &mask, const T bits)
Sets the bits.
constexpr T Bit(const size_t bit)
Return a number with the given bit set to 1 (i.e. 2^bit)
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.