| Contents | Index |
| On this page… |
|---|
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 | Example of Use |
|---|---|---|
FXP_OVERFLOW_SATURATE | Saturate overflows | Not Available |
FXP_OVERFLOW_WRAP | Wrap overflows | Not Available |
Rounding Method Tokens
Token | Description | Example of Use |
|---|---|---|
FXP_ROUND_CEIL | Round to the closest representable number in the direction of positive infinity | Not Available |
FXP_ROUND_CONVERGENT | Round toward nearest integer with ties rounding to nearest even integer | Not Available |
FXP_ROUND_FLOOR | Round to the closest representable number in the direction of negative infinity | Not Available |
FXP_ROUND_NEAR | Round to the closest representable number, with the exact midpoint rounded in the direction of positive infinity | Not Available |
FXP_ROUND_NEAR_ML | Round toward nearest. Ties round toward negative infinity for negative numbers, and toward positive infinity for positive numbers | Not Available |
FXP_ROUND_SIMPLEST | Automatically chooses between round toward floor and round toward zero to produce generated code that is as efficient as possible | Not Available |
FXP_ROUND_ZERO | Round to the closest representable number in the direction of zero | Not Available |
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
![]() | Data Type IDs | Creating MEX-Files | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |