|
Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
Integer math utilities optimized for ARM Cortex-M. More...
#include <integer_math.hpp>
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. | |
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.
|
inlinestaticconstexpr |
Calculate timer prescaler for desired frequency.
Given a base clock frequency and desired output frequency, calculate the best prescaler value.
| base_freq | Base clock frequency (Hz) |
| target_freq | Desired output frequency (Hz) |
Definition at line 76 of file integer_math.hpp.
References divideRounded().
|
inlinestaticconstexpr |
Calculate timer reload value for interval.
Given timer frequency and desired interval, calculate reload value.
| timer_freq | Timer tick frequency (Hz) |
| interval_us | Desired interval (microseconds) |
Definition at line 102 of file integer_math.hpp.
|
inlinestaticconstexpr |
Clamp value to range.
| value | Value to clamp |
| min | Minimum value |
| max | Maximum value |
Definition at line 125 of file integer_math.hpp.
|
inlinestaticconstexpr |
Integer division with rounding.
| dividend | Value to divide |
| divisor | Value to divide by |
Definition at line 62 of file integer_math.hpp.
Referenced by calculatePrescaler().
|
inlinestaticconstexpr |
Calculate greatest common divisor.
| a | First value |
| b | Second value |
Definition at line 35 of file integer_math.hpp.
Referenced by lcm().
|
inlinestaticconstexpr |
Check if value is power of two.
| value | Value to check |
Definition at line 159 of file integer_math.hpp.
|
inlinestaticconstexpr |
Calculate least common multiple.
| a | First value |
| b | Second value |
Definition at line 51 of file integer_math.hpp.
References gcd().
|
inlinestaticconstexpr |
Get maximum of two values.
| a | First value |
| b | Second value |
Definition at line 149 of file integer_math.hpp.
Referenced by clamp().
|
inlinestaticconstexpr |
Get minimum of two values.
| a | First value |
| b | Second value |
Definition at line 137 of file integer_math.hpp.
Referenced by clamp().
|
inlinestaticconstexpr |
Get next power of two.
| value | Input value |
Definition at line 169 of file integer_math.hpp.