Code Generation Rules for Mixed Code
Mixed-mode calculations, i.e. calculations with integer and floating-point elements, are possible in a restricted way:
In the physical code generation, udisc and sdisc elements can be mixed with cont elements without further constraints.
All values are transformed to a floating-point type, and all calculations are done in floating-point.
In the implementation code generation, pure integer calculations can be assigned to a floating-point element.
All values are transformed to a floating-point type, and all calculations are done in floating-point.
In the implementation code generation, pure floating-point calculations can be assigned to an integer element.
All calculations are done in float.
In the implementation code generation, limitInt and wrapInt elements can be mixed with floating-point values.
All calculations with only limitInt/wrapInt operands are done in limitInt/wrapInt (as specified for these types). Calculations that have at least one floating-point operand are done in floating-point.
If a floating-point value is mixed with a value of type linear fixed-point, reciprocal, rescalable, sdisc or udisc, then these elements shall be transformed to the floating-point type before any operation is performed.
The presence of a single floating-point value forces the whole calculation to be performed as floating-point.
If an operation that involves only integer operands is exact (i.e. does not include divisions or overflows), this operation can be performed as integer calculation even in a floating-point context.
This optimization reduces the number of floating-point conversions, and integer operations are more efficient on most microcontrollers. The optimization may also preserve more value bits compared to single-precision floating-point values.
- The rem operator needs two operands of integer model type. Therefore, it does not support mixed-mode calculations.
- The values of model data type sdisc and udisc behave like cont values and are substantially different to limitInt and wrapInt (e.g. if divisions are involved). This is intentional.
Note |
|---|
There is no project property or other option to select between different behavior variants. If the default behavior does not meet your needs, use implementation casts or additional elements to enforce a different behavior. |
See also