| Stateflow User's Guide | ![]() |
Calling the abs Function
Stateflow extends the interpretation of its abs function beyond the standard C version to include integer and floating-point arguments of all types as follows:
x is an integer of type int32, Stateflow evaluates abs(x) with the standard C function abs applied to x, or abs(x).
x is an integer of type other than int32, Stateflow evaluates abs(x) with the standard C abs function applied to a cast of x as an integer of type int32, or abs((int32)x).
x is a floating point number of type double, Stateflow evaluates abs(x) with the standard C function fabs applied to x, or fabs(x).
x is a floating point number of type single, Stateflow evaluates abs(x) with the standard C function fabs applied to a cast of x as a double, or fabs((double)x).
x is a fixed-point number, Stateflow evaluates abs(x) with the standard C function fabs applied to a cast of the fixed-point number as a double, or fabs((double)Vx), where Vx is the real-world value of x.
If you want to use the abs function in Stateflow in the strict sense of standard C, be sure to cast its argument or return values to integer types. See Type Cast Operations.
Note
If x is declared in Stateflow custom code, Stateflow evaluates abs(x) with the standard C abs function in all cases. For instructions on inserting custom code into Stateflow diagrams, see Integrating Custom Code with Stateflow Targets.
|
Calling min and max Functions
Although min and max are not C library functions, Stateflow enables them by emitting the following macros automatically at the top of generated code.
To allow compatibility with user graphical functions named min() or max(), Stateflow generates code for them with a mangled name of the following form: <prefix>_min. However, if you export min() or max() graphical functions to other Stateflow charts in the Stateflow machine, the name of these functions can no longer be emitted with mangled names in generated code and conflict occurs. To avoid this conflict, rename the min() and max() graphical functions.
| Calling C Functions in Actions | Calling User-Written C Code Functions | ![]() |
© 1994-2005 The MathWorks, Inc.