| Stateflow User's Guide | ![]() |
Fixed-Point Operations
Now that you can express fixed-point numbers as
, you can define operations between two fixed-point numbers.
The general equation for an operation between fixed-point operands is as follows:
c = a <op> b
where a, b, and c are all fixed-point numbers, and <op> refers to one of the binary operations: addition, subtraction, multiplication, or division.
The general form for a fixed-point number x is
(see Fixed-Point Numbers). Substituting this form for the result and operands in the preceding equation yields the following:
The values for
and
are usually chosen by Stateflow for each operation (see Promotion Rules for Fixed-Point Operations) and are based on the values for
,
,
, and
, which are entered for each fixed-point data (see Specifying Fixed-Point Data in Stateflow).
Note
Stateflow also offers a more precise means for choosing the values for and when you use the := assignment operator (that is, c := a <op> b). See Assignment (=, :=) Operations for more detail.
|
Using the values for
, and
, you can solve the preceding equation for
for each binary operation as follows:
c=a+b implies that
c=a-b implies that
c=a/b implies that
The fixed-point approximations of the real number result of the operation c = a <op> b are given by the preceding solutions for the value
. In this way, all fixed-point operations are performed using only the stored integer
for each fixed-point number and integer operation.
| Fixed-Point Numbers | Using Fixed-Point Data in Stateflow | ![]() |
© 1994-2005 The MathWorks, Inc.