| Contents | Index |
| On this page… |
|---|
Note You must pay attention to the precision and range of the fixed-point data types and scalings you choose in order to know whether rounding methods will be invoked or if overflows or underflows will occur. |
The range is the span of numbers that a fixed-point data type
and scaling can represent. The range of representable numbers for
a two's complement fixed-point number of word length
, scaling
and bias
is illustrated
below:

For both signed and unsigned fixed-point numbers of any data type, the number of different bit patterns is 2wl.
For example, in two's complement, negative numbers must be represented
as well as zero, so the maximum value is 2wl -1 –
1. Because there is only one representation for
zero, there are an unequal number of positive and negative numbers.
This means there is a representation for
but not for
:

Because a fixed-point data type represents numbers within a finite range, overflows and underflows can occur if the result of an operation is larger or smaller than the numbers in that range.
Fixed-Point Toolbox software allows you to either saturate or wrap overflows. Saturation represents positive overflows as the largest positive number in the range being used, and negative overflows as the largest negative number in the range being used. Wrapping uses modulo arithmetic to cast an overflow back into the representable range of the data type. Refer to Modulo Arithmetic for more information.
When you create a fi object, any overflows are saturated. The OverflowMode property of the default global fimath is saturate. You can log overflows and underflows by setting the LoggingMode property of the fipref object to on. Refer to LoggingMode for more information.
The precision of a fixed-point number is the difference between successive values representable by its data type and scaling, which is equal to the value of its least significant bit. The value of the least significant bit, and therefore the precision of the number, is determined by the number of fractional bits. A fixed-point value can be represented to within half of the precision of its data type and scaling.
For example, a fixed-point representation with four bits to the right of the binary point has a precision of 2-4 or 0.0625, which is the value of its least significant bit. Any number within the range of this data type and scaling can be represented to within (2-4)/2 or 0.03125, which is half the precision. This is an example of representing a number with finite precision.
When you represent numbers with finite precision, not every number in the available range can be represented exactly. If a number cannot be represented exactly by the specified data type and scaling, a rounding method is used to cast the value to a representable number. Although precision is always lost in the rounding operation, the cost of the operation and the amount of bias that is introduced depends on the rounding method itself. To provide you with greater flexibility in the trade-off between cost and bias, Fixed-Point Toolbox software currently supports the following rounding methods:
ceil rounds to the closest representable number in the direction of positive infinity.
convergent rounds to the closest representable number. In the case of a tie, convergent rounds to the nearest even number. This is the least biased rounding method provided by the toolbox.
fix rounds to the closest representable number in the direction of zero.
floor, which is equivalent to two's complement truncation, rounds to the closest representable number in the direction of negative infinity.
nearest rounds to the closest representable number. In the case of a tie, nearest rounds to the closest representable number in the direction of positive infinity. This rounding method is the default for fi object creation and fi arithmetic.
round rounds to the closest representable number. In the case of a tie, the round method rounds:
Positive numbers to the closest representable number in the direction of positive infinity.
Negative numbers to the closest representable number in the direction of negative infinity.
Choosing a Rounding Method. Each rounding method has a set of inherent properties. Depending on the requirements of your design, these properties could make the rounding method more or less desirable to you. By knowing the requirements of your design and understanding the properties of each rounding method, you can determine which is the best fit for your needs. The most important properties to consider are:
Cost — Independent of the hardware being used, how much processing expense does the rounding method require?
Low — The method requires few processing cycles.
Moderate — The method requires a moderate number of processing cycles.
High — The method requires more processing cycles.
Bias — What is the expected value of the rounded
values minus the original values:
?
— The rounding
method introduces a negative bias.
— The rounding
method is unbiased.
— The rounding
method introduces a positive bias.
Possibility of Overflow — Does the rounding method introduce the possibility of overflow?
Yes — The rounded values may exceed the minimum or maximum representable value.
No — The rounded values will never exceed the minimum or maximum representable value.
The following table shows a comparison of the different rounding methods available in both Fixed-Point Toolbox and Simulink® Fixed Point™ products.
| Fixed-Point Toolbox Rounding Method | Simulink Fixed Point Rounding Mode | Cost | Bias | Possibility of Overflow |
|---|---|---|---|---|
| ceil | Ceiling | Low | Large positive | Yes |
| convergent | Convergent | High | Unbiased | Yes |
| fix | Zero | Low |
| No |
| floor | Floor | Low | Large negative | No |
| nearest | Nearest | Moderate | Small positive | Yes |
| round | Round | High |
| Yes |
| N/A | Simplest (Simulink Fixed Point only) | Low | Depends on the operation | No |
![]() | Scaling | Arithmetic Operations | ![]() |

Learn how to apply early verification to your development process through these technical resources.
How much time do you spend on testing to ensure implementation meets system-level requirements?
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |