Stateflow    

Offline and Online Conversions of Fixed-Point Data

Stateflow uses two different techniques for computing the quantized integer, , when converting real numbers into fixed-point quantities: offline and online.

Offline Conversion for Accuracy

Offline conversions are performed during code generation, and are designed to maximize accuracy. They round the resulting quantized integer to its nearest integer value. If the conversion overflows, the result saturates the value for .

Offline conversions are performed for the following operations:

See Offline and Online Conversion Examples.

Online Conversion for Efficiency

Online conversions are performed during execution of the application and are designed to maximize computational efficiency. They are faster and more efficient than offline conversions, but less precise. Instead of rounding to its nearest integer, online conversions round to the floor (with the possible exception of division, which might round to 0, depending on the C compiler you have). If the conversion overflows the type converted to, the result is undefined.

See Offline and Online Conversion Examples.

Offline and Online Conversion Examples

The following are examples of offline and online conversion of the fixed-point type defined by a 16 bit word size, a slope () equal to 2-4, and a bias () equal to 0:



Offline Conversion
Online Conversion






3.45
55.2
55
3.4375
55
3.4375
1.0375
16.6
17
1.0625
16
1
2.06
32.96
33
2.0625
32
2

In the preceding example,


  Tips and Tricks for Using Fixed-Point Data in Stateflow Fixed-Point Context-Sensitive Constants