| Stateflow User's Guide | ![]() |
Fixed-Point Conversion Operations
Stateflow converts real numbers into fixed-point data during data initialization and as part of casting operations in the application. These conversions compute a quantized integer,
, from a real number input. Stateflow uses offline conversions to initialize data and online conversions for casting operations in the running application. The topics that follow describe each conversion type and give examples of the results.
Offline Conversions for Initialized Data
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:
Online Conversions for Casting Operations
Online conversions are performed for casting operations that take place during execution of the application. 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.
Offline and Online Conversion Examples
The following examples show the difference in the results of of offline and online conversions of real numbers to a 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 |
is the real-world value represented as a fixed-point value.
is the floating-point computation for the quantized integer
.
is the rounded value of
.
is the approximate real-world value resulting from
for each conversion.
| Assignment (=, :=) Operations | Autoscaling of Stateflow Fixed-Point | ![]() |
© 1994-2005 The MathWorks, Inc.