Skip to Main Content Skip to Search
Product Documentation

What Is Fixed-Point Data?

Before You Begin

Fixed-point numbers use integers and integer arithmetic to approximate real numbers. They are an efficient means for performing computations involving real numbers without requiring floating-point support in underlying system hardware.

See Tips for Using Fixed-Point Data.

Fixed-Point Numbers

Fixed-point numbers use integers and integer arithmetic to represent real numbers and arithmetic with the following encoding scheme:

where

Fixed-point numbers encode real quantities (for example, 15.375) using the stored integer Q. You set the value of Q by solving the equation

for Q and rounding the result to an integer value as follows:

Q = round((VB)/S)

For example, suppose you want to represent the number 15.375 in a fixed-point type with the slope S = 0.5 and the bias B = 0.1. This means that

Q = round((15.375 – 0.1)/0.5) = 30

However, because Q is rounded to an integer, you lose some precision in representing the number 15.375. If you calculate the number that Q actually represents, you now get a slightly different answer.

Using fixed-point numbers to represent real numbers with integers involves the loss of some precision. However, if you choose S and B correctly, you can minimize this loss to acceptable levels.

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 a binary operation: addition, subtraction, multiplication, or division.

The general form for a fixed-point number x is SxQx + Bx (see Fixed-Point Numbers). Substituting this form for the result and operands in the preceding equation yields this expression:

(ScQc + Bc) = (SaQa + Ba) <op> (SbQb + Bb)

The values for Sc and Bc are chosen by Stateflow software for each operation (see Promotion Rules for Fixed-Point Operations) and are based on the values for Sa, Sb, Ba and Bb that you enter for each fixed-point data (see Specifying Fixed-Point Data).

Using the values for Sa, Sb, Sc, Ba, Bb, and Bc, you can solve the preceding equation for Qc 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 Qc. In this way, all fixed-point operations are performed using only the stored integer Q for each fixed-point number and integer operation.

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS