The API for user-written fixed-point S-functions provides functions
for some mathematical operations, such as conversions. When these
operations are performed, a loss of precision or overflow may occur.
The tokens in the following tables allow you to control the way an
API function handles precision loss and overflow. The data type of
the overflow handling methods is fxpModeOverflow
.
The data type of the rounding modes is fxpModeRounding
.
Overflow Handling Tokens
Token | Description |
---|---|
| Saturate overflows |
| Wrap overflows |
Rounding Method Tokens
Token | Description |
---|---|
| Round to the closest representable number in the direction of positive infinity |
| Round toward nearest integer with ties rounding to nearest even integer |
| Round to the closest representable number in the direction of negative infinity |
| Round to the closest representable number, with the exact midpoint rounded in the direction of positive infinity |
| Round toward nearest. Ties round toward negative infinity for negative numbers, and toward positive infinity for positive numbers |
| Automatically chooses between round toward floor and round toward zero to produce generated code that is as efficient as possible |
| Round to the closest representable number in the direction of zero |
Math functions of the API, such as ssFxpConvert
,
can encounter overflows when carrying out an operation. These functions
provide a mechanism to log the occurrence of overflows and to report
that log back to the caller.
You can use a fixed-point overflow logging structure in your
S-function by defining a variable of data type fxpOverflowLogs
.
Some API functions, such as ssFxpConvert
,
accept a pointer to this structure as an argument. The function initializes
the logging structure and maintains a count of each the following
events that occur while the function is being performed:
Overflows
Saturations
Divide-by-zeros
When a function that accepts a pointer to the logging structure is invoked, the function initializes the event counts of the structure to zero. The requested math operations are then carried out. Each time an event is detected, the appropriate event count is incremented by one.
The following fields contain the event-count information of the structure:
OverflowOccurred
SaturationOccurred
DivisionByZeroOccurred