Logarithmic Functions
/src/math.hppLine 151Computes compile-time binary logarithm (logarithm to the base 2) of an integer.
constexpr std::int32_t log2(std::int32_t n)| Name | Type | Description |
|---|---|---|
n | std::int32_t | The input value. |
constexpr std::int32_t — result The binary logarithm output value.
/src/math.hppLines 699–704Computes the natural logarithm of input variable inp.
Convenience overload that deduces numFracBitsIn from the input type and computes a safe numFracBitsOut.
template <typename T,
FracRepType numFracBitsIn = getNumFractionalBitsOrZero<typename RemoveCore<T>::type>(),
FracRepType numFracBitsOut = calcLogFracBits<numFracBitsIn>()>
decltype(auto) log(const T& inp)| Name | Type | Default | Description |
|---|---|---|---|
T | typename | Input type: qVar_t<FixedPoint<U,F>> for CORE, FixedPoint<U,F> for IMD. | |
numFracBitsIn | FracRepType | getNumFractionalBitsOrZero<typename RemoveCore<T>::type>() | Number of fractional bits in the input, deduced from T. |
numFracBitsOut | FracRepType | calcLogFracBits<numFracBitsIn>() | Number of fractional bits in the output. Defaults to `calcLogFracBits<numFracBitsIn>()`. |
| Name | Type | Description |
|---|---|---|
inp | const T& | The input value. |
decltype(auto) — qVar_t<FixedPoint<U,numFracBitsOut>> for CORE input, FixedPoint<U,numFracBitsOut> for IMD input.
Min, Max, Clip Functions
/src/math.hppLines 1667–1672Clips input to the required range and converts to the required type.
template <typename T, typename InputType>
qVar_t<T> clip(qVar_t<InputType> value,
InputType min = std::numeric_limits<T>::min(),
InputType max = std::numeric_limits<T>::max())| Name | Type | Default | Description |
|---|---|---|---|
T | typename | Type of output. | |
InputType | typename | Type of input. |
| Name | Type | Description |
|---|---|---|
value | qVar_t<InputType> | Value to be converted. |
min | InputType | Min value of a required range. Default is type `T` min value. |
max | InputType | Max value of a required range. Default is type `T` min value. |
qVar_t<T> — qVar_t<T> Converted value within [min, max] range
/src/math.hppLines 111–114Compute variadic min operation, can accept different int and FX types for the arguments as long as they are all signed or all unsigned
template <typename T, std::enable_if_t<same_signed<T, Args...>::value, int> = 0>
std::common_type_t<T, Args...> min(T value, Args... args)| Name | Type | Default | Description |
|---|---|---|---|
T | typename | the type of the first argument |
| Name | Type | Description |
|---|---|---|
value | T | the value of the first argument |
args | Args... | the values of the rest of the arguments |
std::common_type_t<T, Args...> — The min value among the arguments
/src/math.hppLines 85–93Computes the max value in an NDArray.
template <std::size_t numElements, typename NDArrayType>
decltype(auto) max(const NDArrayType& ndArray)| Name | Type | Default | Description |
|---|---|---|---|
numElements | std::size_t | The number of values in the `NDArray`. | |
NDArrayType | typename | Either an NDArray or NDArrayView containing our elements. |
| Name | Type | Description |
|---|---|---|
ndArray | const NDArrayType& | The input array. |
decltype(auto) — The max value.
/src/math.hppLines 111–114Compute variadic min operation, can accept different int and FX types for the arguments as long as they are all signed or all unsigned
template <typename T, std::enable_if_t<same_signed<T, Args...>::value, int> = 0>
std::common_type_t<T, Args...> min(T value, Args... args)| Name | Type | Default | Description |
|---|---|---|---|
T | typename | the type of the first argument |
| Name | Type | Description |
|---|---|---|
value | T | the value of the first argument |
args | Args... | the values of the rest of the arguments |
std::common_type_t<T, Args...> — The min value among the arguments
/src/math.hppLines 125–132Computes the min value in an NDArray.
template <std::size_t numElements, typename T>
T min(const container::NDArray<T, numElements>& ndArray)| Name | Type | Default | Description |
|---|---|---|---|
numElements | std::size_t | The number of values in the `NDArray`. | |
T | typename | The type of the input. |
| Name | Type | Description |
|---|---|---|
ndArray | const container::NDArray<T, numElements>& | The input array. |
T — The min value.
Exponent & Power Functions
/src/math.hppLines 1583–1607Computes the square root of input qInput.
template <FracRepType numFracBitsIn,
FracRepType numFracBitsOut = calcSqrtFracBits<numFracBitsIn>(),
typename T,
IfIntegerTy = 0>
qVar_t<FixedPoint<T, numFracBitsOut>> sqrt(qVar_t<FixedPoint<T, numFracBitsIn>> qInput)| Name | Type | Default | Description |
|---|---|---|---|
numFracBitsIn | FracRepType | Number of bits used for fractional part on input. | |
numFracBitsOut | FracRepType | calcSqrtFracBits<numFracBitsIn>() | Number of bits used for fractional part of output. |
T | typename | The underlying type for the FixedPoint values. |
| Name | Type | Description |
|---|---|---|
qInput | qVar_t<FixedPoint<T, numFracBitsIn>> | The input to the square-root function. |
qVar_t<FixedPoint<T, numFracBitsOut>> — qVar_t<FixedPoint<T, numFracBitsOut>> The output to the square-root function.


/src/math.hppLines 857–882Computes the natural exponent of input variable inp.
Primary overload requiring explicit numFracBitsIn. expMethod and numFracBitsOut have defaults and do not need to be specified unless overriding. Use the convenience overload below for automatic deduction of numFracBitsIn from FixedPoint input types.
template <FracRepType numFracBitsIn,
ExpMethod expMethod = ExpMethod::FAST,
FracRepType numFracBitsOut = numFracBitsIn,
typename T>
decltype(auto) exp(const T& inp)| Name | Type | Default | Description |
|---|---|---|---|
numFracBitsIn | FracRepType | Number of fractional bits in the input. | |
expMethod | ExpMethod | ExpMethod::FAST | Algorithm: ExpMethod::FAST (default) or ExpMethod::REMEZ (more accurate). |
numFracBitsOut | FracRepType | numFracBitsIn | Number of fractional bits in the output. |
T | typename | Input type: qVar_t<FixedPoint<U,F>>, FixedPoint<U,F>, qVar_t<U>, or integer U. |
| Name | Type | Description |
|---|---|---|
inp | const T& | The input value. |
decltype(auto) — qVar_t<FixedPoint<U,F>>, FixedPoint<U,F>, qVar_t<U>, or integer U.
ExpMethod::REMEZ

/src/math.hppLines 919–1000Computes runtime Pow of input variable.
template <typename InpType,
typename ExpType,
FracRepType numFracBitsOut = getNumFractionalBitsOrZero<InpType>(),
IfNotIntegerTy = 0>
INLINE decltype(auto) pow(const InpType& inp, const ExpType& exponent)| Name | Type | Default | Description |
|---|---|---|---|
InpType | typename | The input type of the base. | |
ExpType | typename | The input type of the exponent. | |
numFracBitsOut | FracRepType | getNumFractionalBitsOrZero<InpType>() |
| Name | Type | Description |
|---|---|---|
inp | const InpType& | The input value. |
exponent | const ExpType& | The exponent value. |
INLINE decltype(auto) — FixedPoint32<numFracBitsOut> or qVar<FixedPoint32<numFracBitsOut>> The power of input 'inp' with exponent 'exponent'.
Trigonometric Functions
/src/math.hppLines 1266–1277Computes the cosine of input FixedPoint angle.
template <bool transformRange = false,
FracRepType outNumFracBitsVal = 32,
typename OutT = std::int32_t,
typename AngleType>
decltype(auto) cos(const AngleType& inp)| Name | Type | Default | Description |
|---|---|---|---|
transformRange | bool | false | Whether to transform the input angle to [-pi/2, pi/2] range. Allows input with arbitrary value, produces additional overhead. |
outNumFracBitsVal | FracRepType | 32 | Number of bits to be used for fractional part in the output `FixedPoint` |
OutT | typename | std::int32_t | Underlying type of the output `FixedPoint`, defaults to `std::int32_t` |
AngleType | typename | Type of the input angle, expected to be a `FixedPoint` |
| Name | Type | Description |
|---|---|---|
inp | const AngleType& | The input angle in radians, as a `FixedPoint` |
decltype(auto) — The cosine of input `FixedPoint`.

/src/math.hppLines 1237–1248Computes the sine of input FixedPoint angle.
template <bool transformRange = false,
FracRepType outNumFracBitsVal = 32,
typename OutT = std::int32_t,
typename AngleType>
decltype(auto) sin(const AngleType& inp)| Name | Type | Default | Description |
|---|---|---|---|
transformRange | bool | false | Whether to transform the input angle to [-pi/2, pi/2] range. Allows input with arbitrary value, produces additional overhead. |
outNumFracBitsVal | FracRepType | 32 | Number of bits to be used for fractional part in the output `FixedPoint` |
OutT | typename | std::int32_t | Underlying type of the output `FixedPoint`, defaults to `std::int32_t` |
AngleType | typename | Type of the input angle, expected to be a `FixedPoint` |
| Name | Type | Description |
|---|---|---|
inp | const AngleType& | The input angle in radians, as a `FixedPoint` |
decltype(auto) — The sine of input `FixedPoint`.

Round & Truncate
/src/math.hppLines 1472–1485Rounds the input fixed-point value to the nearest integer in the same fixed point representation.
Ties in case of half-integer fixed-points are resolved by the specified rounding method.
template <RoundMethod t,
FracRepType numFracBits,
typename T,
std::enable_if_t<t != RoundMethod::awayFromZero, bool> = 0>
qVar_t<FixedPoint<T, numFracBits>> round(qVar_t<FixedPoint<T, numFracBits>> inp)| Name | Type | Default | Description |
|---|---|---|---|
t | RoundMethod | `math::RoundMethod` to be used for tie resolution (default: `RoundMethod::towardsPositiveInfinity`). | |
numFracBits | FracRepType | Number of fractional bits used in the fixed point representation. | |
T | typename | Underlying type of the `FixedPoint` input. |
| Name | Type | Description |
|---|---|---|
inp | qVar_t<FixedPoint<T, numFracBits>> | Input value to be rounded to the nearest integer in same fixed-point representation. |
qVar_t<FixedPoint<T, numFracBits>> — Rounded fixed-point value.
/src/math.hppLines 1301–1309Truncates the input to the nearest integer towards negative infinity.
Note: Unlike <code><a href="https://en.cppreference.com/w/cpp/numeric/math/trunc">std::trunc</a></code> which truncates towards zero, this function truncates towards negative infinity. For example,
std::trunc(-2.7) == -2.0
chimera::math::trunc(-2.7) == -3.0 // The double values are representative of the fixed point values.
template <FracRepType numFracBits,
typename T,
std::enable_if_t<IsFixedPoint<typename RemoveCore<T>::type>::value, bool> = 0>
T trunc(const T& inp)| Name | Type | Default | Description |
|---|---|---|---|
numFracBits | FracRepType | Number of fractional bits in the input `FixedPoint`. | |
T | typename | Type of input value. |
| Name | Type | Description |
|---|---|---|
inp | const T& | Input fixed point number. |
T — Nearest integer towards negative infinity. / // clang-format on
