Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
sbl::core::primitives::math::IntegerMath Class Reference

Integer math utilities optimized for ARM Cortex-M. More...

#include <integer_math.hpp>

Collaboration diagram for sbl::core::primitives::math::IntegerMath:

Static Public Member Functions

static constexpr uint32_t gcd (uint32_t a, uint32_t b)
 Calculate greatest common divisor.
 
static constexpr uint32_t lcm (uint32_t a, uint32_t b)
 Calculate least common multiple.
 
static constexpr uint32_t divideRounded (uint32_t dividend, uint32_t divisor)
 Integer division with rounding.
 
static constexpr uint32_t calculatePrescaler (uint32_t base_freq, uint32_t target_freq)
 Calculate timer prescaler for desired frequency.
 
static constexpr uint32_t calculateTimerReload (uint32_t timer_freq, uint32_t interval_us)
 Calculate timer reload value for interval.
 
template<typename T >
static constexpr T clamp (T value, T min, T max)
 Clamp value to range.
 
template<typename T >
static constexpr T min (T a, T b)
 Get minimum of two values.
 
template<typename T >
static constexpr T max (T a, T b)
 Get maximum of two values.
 
static constexpr bool isPowerOfTwo (uint32_t value)
 Check if value is power of two.
 
static constexpr uint32_t nextPowerOfTwo (uint32_t value)
 Get next power of two.
 

Detailed Description

Integer math utilities optimized for ARM Cortex-M.

Static utility functions for common mathematical operations using only integer arithmetic.

Definition at line 26 of file integer_math.hpp.

Member Function Documentation

◆ calculatePrescaler()

static constexpr uint32_t sbl::core::primitives::math::IntegerMath::calculatePrescaler ( uint32_t  base_freq,
uint32_t  target_freq 
)
inlinestaticconstexpr

Calculate timer prescaler for desired frequency.

Given a base clock frequency and desired output frequency, calculate the best prescaler value.

Parameters
base_freqBase clock frequency (Hz)
target_freqDesired output frequency (Hz)
Returns
Prescaler value (1-65536)

Definition at line 76 of file integer_math.hpp.

References divideRounded().

Here is the call graph for this function:

◆ calculateTimerReload()

static constexpr uint32_t sbl::core::primitives::math::IntegerMath::calculateTimerReload ( uint32_t  timer_freq,
uint32_t  interval_us 
)
inlinestaticconstexpr

Calculate timer reload value for interval.

Given timer frequency and desired interval, calculate reload value.

Parameters
timer_freqTimer tick frequency (Hz)
interval_usDesired interval (microseconds)
Returns
Timer reload value

Definition at line 102 of file integer_math.hpp.

◆ clamp()

template<typename T >
static constexpr T sbl::core::primitives::math::IntegerMath::clamp ( value,
min,
max 
)
inlinestaticconstexpr

Clamp value to range.

Parameters
valueValue to clamp
minMinimum value
maxMaximum value
Returns
Clamped value

Definition at line 125 of file integer_math.hpp.

References max(), and min().

Here is the call graph for this function:

◆ divideRounded()

static constexpr uint32_t sbl::core::primitives::math::IntegerMath::divideRounded ( uint32_t  dividend,
uint32_t  divisor 
)
inlinestaticconstexpr

Integer division with rounding.

Parameters
dividendValue to divide
divisorValue to divide by
Returns
Rounded result

Definition at line 62 of file integer_math.hpp.

Referenced by calculatePrescaler().

Here is the caller graph for this function:

◆ gcd()

static constexpr uint32_t sbl::core::primitives::math::IntegerMath::gcd ( uint32_t  a,
uint32_t  b 
)
inlinestaticconstexpr

Calculate greatest common divisor.

Parameters
aFirst value
bSecond value
Returns
Greatest common divisor

Definition at line 35 of file integer_math.hpp.

Referenced by lcm().

Here is the caller graph for this function:

◆ isPowerOfTwo()

static constexpr bool sbl::core::primitives::math::IntegerMath::isPowerOfTwo ( uint32_t  value)
inlinestaticconstexpr

Check if value is power of two.

Parameters
valueValue to check
Returns
true if power of two

Definition at line 159 of file integer_math.hpp.

◆ lcm()

static constexpr uint32_t sbl::core::primitives::math::IntegerMath::lcm ( uint32_t  a,
uint32_t  b 
)
inlinestaticconstexpr

Calculate least common multiple.

Parameters
aFirst value
bSecond value
Returns
Least common multiple

Definition at line 51 of file integer_math.hpp.

References gcd().

Here is the call graph for this function:

◆ max()

template<typename T >
static constexpr T sbl::core::primitives::math::IntegerMath::max ( a,
b 
)
inlinestaticconstexpr

Get maximum of two values.

Parameters
aFirst value
bSecond value
Returns
Maximum value

Definition at line 149 of file integer_math.hpp.

Referenced by clamp().

Here is the caller graph for this function:

◆ min()

template<typename T >
static constexpr T sbl::core::primitives::math::IntegerMath::min ( a,
b 
)
inlinestaticconstexpr

Get minimum of two values.

Parameters
aFirst value
bSecond value
Returns
Minimum value

Definition at line 137 of file integer_math.hpp.

Referenced by clamp().

Here is the caller graph for this function:

◆ nextPowerOfTwo()

static constexpr uint32_t sbl::core::primitives::math::IntegerMath::nextPowerOfTwo ( uint32_t  value)
inlinestaticconstexpr

Get next power of two.

Parameters
valueInput value
Returns
Next power of two >= value

Definition at line 169 of file integer_math.hpp.


The documentation for this class was generated from the following file: