Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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.

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

$$V=\stackrel{\sim}{V}=SQ+B$$

where

is a precise real-world value that you want to approximate with a fixed-point number.*V*$$\stackrel{\sim}{V}$$ is the approximate real-world value that results from fixed-point representation.

is an integer that encodes $$\stackrel{\sim}{V.}$$ This value is the*Q**quantized integer.*is the actual stored integer value used in representing the fixed-point number. If a fixed-point number changes, its quantized integer,*Q*, changes but*Q*and*S*remain unchanged.*B*is a coefficient of*S*, or the*Q**slope*.is an additive correction, or the*B**bias*.

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

$$\stackrel{\sim}{V}=SQ+B$$

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

* Q* = round((

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

* 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

$$V=\stackrel{\sim}{V}=SQ+B=0.5\times 30+0.1=15.1$$

Using fixed-point numbers to represent real numbers with integers
involves the loss of some precision. However, if you choose * S* and

Now that you can express fixed-point numbers as $$\stackrel{\sim}{V}=SQ+B,$$ 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 *S*_{x}*Q*_{x} + *B*_{x} (see Fixed-Point Numbers).
Substituting this form for the result and operands in the preceding
equation yields this expression:

(*S _{c}*

`op`

> (The values for * S_{c}* and

when
you use the B_{c}`:=` assignment operator (that is, ```
c
:= a <
``` ). See Assignment (=, :=) Operations. |

Using the values for * S_{a}*,

The operation

`c=a+b`

implies that= ((*Q*_{c}/*S*_{a})*S*_{c}+ (*Q*_{a}/*S*_{b}*S*_{c})+ (*Q*_{b}+*B*_{a}–*B*_{b})/*B*_{c})*S*_{c}The operation

`c=a-b`

implies that= ((*Q*_{c}/*S*_{a})*S*_{c}– (*Q*_{a}/*S*_{b})*S*_{c}– (*Q*_{b}–*B*_{a}–*B*_{b})/*B*_{c})*S*_{c}The operation

`c=a*b`

implies that= ((*Q*_{c}*S*_{a}/*S*_{b})*S*_{c}*Q*_{a}+ (*Q*_{b}*B*_{a}/*S*_{b})*S*_{c}+ (*Q*_{a}*B*_{b}/*S*_{a})*S*_{c}+ (*Q*_{b}*B*_{a}–*B*_{b})/*B*_{c})*S*_{c}The operation

`c=a/b`

implies that= ((*Q*_{c}*S*_{a}+*Q*_{a})/(*B*_{a}(*S*_{c}*S*_{b}+*Q*_{b})) – (*B*_{b}/*B*_{c}))*S*_{c}

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 * Q_{c}*.
In this way, all fixed-point operations are performed using only the
stored integer

Was this topic helpful?