Stateflow User's Guide Previous page   Next Page

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:

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).

Using the values for , and , you can solve the preceding equation for for each binary operation as follows:

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.


Previous page  Fixed-Point Numbers Using Fixed-Point Data in Stateflow Next page

© 1994-2005 The MathWorks, Inc.