Jump to main content

##

# 3.11.7 Q15_MULTIPLY_SAT Macro

## C

    #define   Q15_MULTIPLY_SAT(x, y) ({                \
        int32_t result = ((int32_t)(x) * (int32_t)(y)) >> 15U; \
        if (result > INT16_MAX) result = INT16_MAX;            \
        else if (result < INT16_MIN) result = INT16_MIN;       \
        (int16_t)result;                                       \
    })

## Summary

Performs multiplication of two fixed-point numbers represented in Q15 format and.

## Description

This macro performs multiplication of two Q15 (fixed-point) numbers with saturation handling. It ensures that the result does not exceed the range of a Q15 value, which is between `-32768` (`INT16_MIN`) and `32767` (`INT16_MAX`).

## Example

    int16_t a = 20000;  // Approximately 0.61035 in Q15
    int16_t b = 20000;  // Approximately 0.61035 in Q15

    int16_t result = Q15_MULTIPLY_SAT(a, b);  // Expected to handle saturation if needed

## Remarks

None