Fixposition SDK 0.0.0-heads/main-0-g90a51ff
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
fpsdk::common::math Namespace Reference

Math utilities. More...

Functions

template<typename T >
constexpr T Clamp (const T val, const T min, const T max)
 Clamp value in range.
 
template<typename T >
constexpr T DegToRad (T degrees)
 Convert degrees to radians.
 
template<typename T >
constexpr T RadToDeg (T radians)
 Convert radians to degrees.
 
double RoundToFracDigits (const double value, const int digits)
 Round to desired number of fractional digits (of precision)
 
Bit manipulation functions

Examples:

uint8_t mask = 0;
SetBits(mask, Bit(0) | Bit(1) | Bit(7)); // mask is now 0x83
const bool bit_7_is_set = CheckBits(mask, Bit(7)); // true
void SetBits(T &mask, const T bits)
Sets the bits.
Definition math.hpp:176
constexpr T Bit(const size_t bit)
Return a number with the given bit set to 1 (i.e. 2^bit)
Definition math.hpp:118
template<typename T >
constexpr T Bit (const size_t bit)
 Return a number with the given bit set to 1 (i.e. 2^bit)
 
template<typename T >
constexpr bool CheckBitsAll (const T mask, const T bits)
 Checks if all bits are set.
 
template<typename T >
constexpr bool CheckBitsAny (const T mask, const T bits)
 Checks if any bits are set.
 
template<typename T >
constexpr T GetBits (const T value, const T mask)
 Extracts bits.
 
template<typename T >
void SetBits (T &mask, const T bits)
 Sets the bits.
 
template<typename T >
void ClearBits (T &mask, const T bits)
 Clears the bits.
 
template<typename T >
void ToggleBits (T &mask, const T bits)
 Toggles the bits.
 

Detailed Description

Math utilities.

Function Documentation

◆ Clamp()

template<typename T >
T fpsdk::common::math::Clamp ( const T val,
const T min,
const T max )
constexpr

Clamp value in range.

Template Parameters
Tnumeric type
Parameters
[in]valThe value
[in]minMinimum value
[in]maxMaximum value
Note
c++-17 has std::clamp() doing exactly (?) this...
Returns
the value clamped to the given range

Definition at line 51 of file math.hpp.

◆ DegToRad()

template<typename T >
T fpsdk::common::math::DegToRad ( T degrees)
inlineconstexpr

Convert degrees to radians.

Template Parameters
Tvalue type
Parameters
[in]degreesAngle in degrees
Returns
the angle in radians

Definition at line 65 of file math.hpp.

◆ RadToDeg()

template<typename T >
T fpsdk::common::math::RadToDeg ( T radians)
inlineconstexpr

Convert radians to degrees.

Template Parameters
Tvalue type
Parameters
[in]radiansAngle in radians
Returns
the angle in radians

Definition at line 79 of file math.hpp.

◆ RoundToFracDigits()

double fpsdk::common::math::RoundToFracDigits ( const double value,
const int digits )

Round to desired number of fractional digits (of precision)

Parameters
[in]valueThe value
[in]digitsNumber of digits (0-12), param clamped to range
Returns
the value rounded to the given number of fractional digits, or the original value if it is not finite

◆ Bit()

template<typename T >
T fpsdk::common::math::Bit ( const size_t bit)
constexpr

Return a number with the given bit set to 1 (i.e. 2^bit)

Template Parameters
TNumerical type
Parameters
[in]bitbit to be set to 1 (0-63, depending on T, 0 = LSB)
Returns
the mask (value) with the desired bit set

Definition at line 118 of file math.hpp.

◆ CheckBitsAll()

template<typename T >
bool fpsdk::common::math::CheckBitsAll ( const T mask,
const T bits )
constexpr

Checks if all bits are set.

Template Parameters
TNumerical type
Parameters
[in]maskMask (value) that should be checked
[in]bitsBit(s) to be checked
Returns
true if all bit(s) is (are) set, false otherwise

Definition at line 133 of file math.hpp.

◆ CheckBitsAny()

template<typename T >
bool fpsdk::common::math::CheckBitsAny ( const T mask,
const T bits )
constexpr

Checks if any bits are set.

Template Parameters
TNumerical type
Parameters
[in]maskMask (value) to be checked
[in]bitsBit(s) to be checked
Returns
true if any bit(s) is (are) set, false otherwise

Definition at line 148 of file math.hpp.

◆ GetBits()

template<typename T >
T fpsdk::common::math::GetBits ( const T value,
const T mask )
constexpr

Extracts bits.

Template Parameters
TNumerical type
Parameters
[in]valueThe bitfield value
[in]maskMask of bits that should be extracted
Returns
the extracted bits

Definition at line 163 of file math.hpp.

◆ SetBits()

template<typename T >
void fpsdk::common::math::SetBits ( T & mask,
const T bits )
inline

Sets the bits.

Template Parameters
TNumerical type
Parameters
[in,out]maskMask (value) to be modified
[in]bitsBit(s) to be set

Definition at line 176 of file math.hpp.

◆ ClearBits()

template<typename T >
void fpsdk::common::math::ClearBits ( T & mask,
const T bits )
inline

Clears the bits.

Template Parameters
TNumerical type
Parameters
[in,out]maskMask (value) to be modified
[in]bitsBit(s) to be cleared

Definition at line 189 of file math.hpp.

◆ ToggleBits()

template<typename T >
void fpsdk::common::math::ToggleBits ( T & mask,
const T bits )
inline

Toggles the bits.

Template Parameters
TNumerical type
Parameters
[in,out]maskMask (value) to be modified
[in]bitsBit(s) to be toggled

Definition at line 202 of file math.hpp.