| Stateflow User's Guide | ![]() |
Fixed-Point Numbers
Fixed-point numbers use integers and integer arithmetic to represent real numbers and arithmetic with the following encoding scheme:
is a precise real-world value that you want to approximate with a fixed-point number.
is the approximate real-world value that results from fixed-point representation.
is an integer that encodes
. It is referred to as the quantized integer.
is the actual stored integer value used in representing the fixed-point number; that is, if a fixed-point number changes, its quantized integer,
, changes --
and
remain unchanged.
Fixed-point numbers encode real quantities (for example, 15.375) using the stored integer
. You set
's value by solving the preceding equation
for
and rounding the result to an integer value as follows:
For example, suppose you want to represent the number 15.375 in a fixed-point type with the slope
and the bias
. This means that
However, because
is rounded to an integer, you have lost some precision in representing the number 15.375. If you calculate the number that
actually represents, you now get a slightly different answer.
So using fixed-point numbers to represent real numbers with integers involves the loss of some precision. However, if you choose
and
correctly, you can minimize this loss to acceptable levels.
| What Is Fixed-Point Data? | Fixed-Point Operations | ![]() |
© 1994-2005 The MathWorks, Inc.