| Stateflow User's Guide | ![]() |
How Stateflow Defines Fixed-Point Data
The preceding example in What Is Fixed-Point Data? does not answer the question of how the values for the slope,
, the quantized integer,
, and the bias,
, are implemented in Stateflow as integers. These values are implemented through the following:
You specify values for
,
, and the base integer type for
. The available base types for
are the unsigned integer types uint8, uint16, and uint32, and the signed integer types int8, int16, and int32. For specific instructions on how to enter fixed-point data, see Specifying Fixed-Point Data in Stateflow.
Notice that if a fixed-point number has a slope
and a bias
, it is equivalent to its quantized integer
, and behaves exactly as its base integer type.
This is the only part of a fixed-point number that varies in value. The quantities
and
are constant and appear only as literal numbers or expressions in generated code.
The powers of 2 are implemented as bit shifts, which are more efficient than multiply instructions. Setting
avoids the computationally expensive multiply instructions for values of
. This is referred to as binary-point-only scaling, which is implemented with bit shifts only, and is highly recommended.
To generate efficient code, the fixed-point promotion rules choose values for
and
that conveniently cancel out difficult terms in the solutions. See Addition (+) and Subtraction (-) and Multiplication (*) and Division (/).
Stateflow provides a special assignment operator (:=) and context-sensitive constants to help you maintain as much precision as possible in your fixed-point operations. See Assignment (=, :=) Operations and Fixed-Point Context-Sensitive Constants.
, that cannot be expressed as a pure integer or a power of 2, are converted into fixed-point numbers.
These remaining numbers can be computationally expensive in multiplication and division operations. That is why the practice of using binary-point-only scaling in which
and
is recommended.
| Using Fixed-Point Data in Stateflow | Specifying Fixed-Point Data in Stateflow | ![]() |
© 1994-2005 The MathWorks, Inc.