UH-OH

It looks like you don’t have access to that feature yet

Contact sales to get upgraded to the full DevStudio experience.

UH-OH

It looks like you don't have access to that feature yet.

to select
to navigate
escto close
Chimera Compute Library (CCL) API ReferenceElementary Math Functions

Elementary Math Functions

Logarithmic Functions

File: /src/math.hppLines 141–147
    /**
     * @brief   Computes compile-time binary logarithm (logarithm to the base 2) of an integer.
     * @ingroup qmath_ops
     * @param[in] n The input value.
     * @return    result  The binary logarithm output value.
     **/
    constexpr std::int32_t log2(std::int32_t n) { return ((n < 2) ? 0 : 1 + log2(n / 2)); }
File: /src/math.hppLines 547–569
    /**
     * @brief   Computes the natural logarithm of input variable `inp`.
     * @ingroup qmath_ops
     *
     * Convenience overload that deduces numFracBitsIn from the input type for FixedPoint inputs
     * and computes a safe numFracBitsOut.
     * For integer (non-FixedPoint) inputs, numFracBitsIn must be provided explicitly.
     *
     * @tparam    T              Input type: qVar_t<FixedPoint<U,F>>, FixedPoint<U,F>, qVar_t<U>, or integer U.
     * @tparam    numFracBitsIn  Number of fractional bits in the input. Deduced automatically from T
     *                           for FixedPoint inputs; must be specified explicitly for integer inputs.
     * @tparam    numFracBitsOut Number of fractional bits in the output.
     *                           Defaults to `calcLogFracBits<numFracBitsIn>()`.
     * @param[in] inp            The input value.
     * @return   qVar_t<FixedPoint<U,numFracBitsOut>> for CORE FixedPoint input,
     *           FixedPoint<U,numFracBitsOut>         for IMD  FixedPoint input,
     *           qVar_t<int32_t>                      for CORE integer input,
     *           int32_t                              for IMD  integer input.
     **/
    template <typename T,
              FracRepType numFracBitsIn  = getNumFractionalBitsOrZero<typename RemoveCore<T>::type>(),
              FracRepType numFracBitsOut = calcLogFracBits<numFracBitsIn>()>
    decltype(auto) log(const T& inp) {

Min, Max, Clip Functions

File: /src/math.hppLines 1682–1694
     * @brief Clips input to the required range and converts to the required type.
     *
     * @tparam T Type of output.
     * @tparam InputType Type of input.
     * @param value Value to be converted.
     * @param min Min value of a required range. Default is type `T` min value.
     * @param max Max value of a required range. Default is type `T` min value.
     * @return     qVar_t<T>            Converted value within [min, max] range
     */
    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()) {
File: /src/math.hppLines 98–109
    /**
     * @brief Compute variadic min operation, can accept different int and FX types
     * for the arguments as long as they are all signed or all unsigned
     *
     * @tparam T the type of the first argument
     * @tparam Args the types for the rest of the arguments
     * @param value the value of the first argument
     * @param args the values of the rest of the arguments
     * @return The min value among the arguments
     */
    template <typename T, typename... Args, std::enable_if_t<same_signed<T, Args...>::value, int> = 0>
    std::common_type_t<T, Args...> min(T value, Args... args) {
File: src/math.hppLines 75–84
    /**
     * @brief Computes the max value in an `NDArray`.
     *
     * @tparam numElements The number of values in the `NDArray`.
     * @tparam NDArrayType Either an NDArray or NDArrayView containing our elements.
     * @param ndArray The input array.
     * @return The max value.
     */
    template <std::size_t numElements, typename NDArrayType>
    decltype(auto) max(const NDArrayType& ndArray) {
File: /src/math.hppLines 98–109
    /**
     * @brief Compute variadic min operation, can accept different int and FX types
     * for the arguments as long as they are all signed or all unsigned
     *
     * @tparam T the type of the first argument
     * @tparam Args the types for the rest of the arguments
     * @param value the value of the first argument
     * @param args the values of the rest of the arguments
     * @return The min value among the arguments
     */
    template <typename T, typename... Args, std::enable_if_t<same_signed<T, Args...>::value, int> = 0>
    std::common_type_t<T, Args...> min(T value, Args... args) {
File: /src/math.hppLines 113–122
    /**
     * @brief Computes the min value in an `NDArray`.
     *
     * @tparam numElements The number of values in the `NDArray`.
     * @tparam T The type of the input.
     * @param ndArray The input array.
     * @return The min value.
     */
    template <std::size_t numElements, typename T>
    T min(const container::NDArray<T, numElements>& ndArray) {

Exponent & Power Functions

File: /src/math.hppLines 1646–1659
    /**
     * @brief Computes the square root of input `qInput`.
     *
     * @tparam numFracBitsIn Number of bits used for fractional part on input.
     * @tparam numFracBitsOut Number of bits used for fractional part of output.
     * @tparam T The underlying type for the FixedPoint values.
     * @param qInput The input to the square-root function.
     * @return qVar_t<FixedPoint<T, numFracBitsOut>> The output to the square-root function.
     */
    template <FracRepType numFracBitsIn,
              FracRepType numFracBitsOut = calcSqrtFracBits<numFracBitsIn>(),
              typename T,
              IfIntegerTy<T> = 0>
    qVar_t<FixedPoint<T, numFracBitsOut>> sqrt(qVar_t<FixedPoint<T, numFracBitsIn>> qInput) {

File: /src/math.hppLines 701–721
    /**
     * @brief   Computes the natural exponent of input variable `inp`.
     * @ingroup qmath_ops
     *
     * 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.
     *
     * @tparam numFracBitsIn  Number of fractional bits in the input.
     * @tparam numFracBitsOut Number of fractional bits in the output.
     * @tparam expMethod      Algorithm: ExpMethod::FAST (default) or ExpMethod::REMEZ (more accurate).
     * @tparam T              Input type: qVar_t<FixedPoint<U,F>>, FixedPoint<U,F>, qVar_t<U>, or integer U.
     * @param[in] inp         The input value.
     * @return qVar_t<FixedPoint<U,F>>, FixedPoint<U,F>, qVar_t<U>, or integer U.
     **/

    template <FracRepType numFracBitsIn,
              ExpMethod   expMethod      = ExpMethod::FAST,
              FracRepType numFracBitsOut = numFracBitsIn,
              typename T>
    decltype(auto) exp(const T& inp) {

ExpMethod::REMEZ

File: /src/math.hppLines 765–781
    /**
     * @brief Computes runtime Pow of input variable.
     * @ingroup qmath_ops
     *
     * @tparam InpType The input type of the base.
     * @tparam ExpType The input type of the exponent.
     * @tparam numFracBitsOut
     * @param inp The input value.
     * @param exponent The exponent value.
     * @return FixedPoint32<numFracBitsOut> or qVar<FixedPoint32<numFracBitsOut>> The power of input 'inp' with exponent
     * 'exponent'.
     */
    template <typename InpType,
              typename ExpType,
              FracRepType numFracBitsOut = getNumFractionalBitsOrZero<InpType>(),
              IfNotIntegerTy<ExpType>    = 0>
    INLINE decltype(auto) pow(const InpType& inp, const ExpType& exponent) {

Trigonometric Functions

File: /src/math.hppLines 1178–1198
    /**
     * @brief     Computes the cosine of input `FixedPoint` angle.
     *
     * @ingroup   qmath_ops
     *
     * @tparam    transformRange  Whether to transform the input angle to [-pi/2, pi/2] range. Allows input with
     *                            arbitrary value, produces additional overhead.
     * @tparam    _outNumFracBits Number of bits to be used for fractional part in the output `FixedPoint`
     * @tparam    OutT            Underlying type of the output `FixedPoint`, defaults to `std::int32_t`
     * @tparam    AngleType       Type of the input angle, expected to be a `FixedPoint`
     * @tparam    ReturnType      Expected output type, defaults to `AngleType`
     *
     * @param[in] inp             The input angle in radians, as a `FixedPoint`
     *
     * @return    The cosine of input `FixedPoint`.
     */
    template <bool        transformRange  = false,
              FracRepType _outNumFracBits = 32,  // NOLINT; 32 := unspecified precision
              typename OutT               = std::int32_t,
              typename AngleType>
    decltype(auto) cos(const AngleType& inp) {

File: /src/math.hppLines 1139–1159
    /**
     * @brief     Computes the sine of input `FixedPoint` angle.
     *
     * @ingroup   qmath_ops
     *
     * @tparam    transformRange  Whether to transform the input angle to [-pi/2, pi/2] range. Allows input with
     *                            arbitrary value, produces additional overhead.
     * @tparam    _outNumFracBits Number of bits to be used for fractional part in the output `FixedPoint`
     * @tparam    OutT            Underlying type of the output `FixedPoint`, defaults to `std::int32_t`
     * @tparam    AngleType       Type of the input angle, expected to be a `FixedPoint`
     * @tparam    ReturnType      Expected output type, defaults to `AngleType`
     *
     * @param[in] inp             The input angle in radians, as a `FixedPoint`
     *
     * @return    The sine of input `FixedPoint`.
     */
    template <bool        transformRange  = false,
              FracRepType _outNumFracBits = 32,  // NOLINT; 32 := unspecified precision
              typename OutT               = std::int32_t,
              typename AngleType>
    decltype(auto) sin(const AngleType& inp) {

Round & Truncate

File: /src/math.hppLines 1390–1406
    /**
     * @brief  Rounds 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.
     *
     * @tparam t           `math::RoundMethod` to be used for tie resolution (default: `RoundMethod::awayFromZero`).
     * @tparam numFracBits Number of fractional bits used in the fixed point representation.
     * @tparam T           Underlying type of the `FixedPoint` input.
     * @param  inp         Input value to be rounded to the nearest integer in same fixed-point representation.
     *
     * @return Rounded fixed-point value.
     */
    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) {
File: /src/math.hppLines 1220–1241
    /**
     * @brief  Truncates 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.
     *  ```
     *
     * @tparam numFracBits Number of fractional bits in the input `FixedPoint`.
     * @tparam T           Type of input value.
     * @param  inp         Input fixed point number.
     *
     * @return Nearest integer towards negative infinity.
     */
    // clang-format on
    template <FracRepType numFracBits,
              typename T,
              std::enable_if_t<IsFixedPoint<typename RemoveCore<T>::type>::value, bool> = 0>
    T trunc(const T& inp) {
Table of Contents


© Copyright 2026 Quadric All Rights Reserved • Privacy Policy
This documentation is preliminary and confidential. It is subject to change. Quadric does not give any warranty express or implied that the contents will be complete or accurate or up to date. The company shall not be liable for any loss, actions, claims, proceedings, demands or costs or damages whatsoever or howsoever caused arising directly or indirectly in connection with or arising out of the use of this material.

Sign in to your account

Don't have an account? Create an Account
By signing in, you are agreeing to our Terms of Use and Privacy Policy.

Develop.

Simulate.

Profile.

Collaborate.

We use cookies to enhance your browsing experience, and analyze our traffic.
By clicking "Accept All", you consent to our use of cookies.