Rounding Modes
When you represent numbers with finite precision, not every number in the available range can be represented exactly. The result of any operation on a fixed-point number is typically stored in a register that is longer than the number's original format. When the result is put back into the original format, a rounding method is used to cast the value to a representable number. Precision is always lost in the rounding operation, and produces quantization errors and computational noise. The cost of the rounding operation and the amount of bias that is introduced depends on the rounding method itself.
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.
Note
The cost estimates provided here are hardware independent. Some processors have rounding modes built-in, so consider carefully the hardware you are using before calculating the true cost of each rounding mode.
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.
Fixed-Point Designer Rounding Modes
To provide you with greater flexibility in the tradeoff between cost and bias, the Fixed-Point Designer™ product currently supports the following rounding methods:
Fixed-Point Designer Rounding Mode | Description | Tie Handling | Cost | Bias |
---|---|---|---|---|
Ceiling | Rounds to the nearest representable number in the direction of positive infinity. | N/A | Low | Large positive |
Convergent | Rounds to the nearest representable number. | Ties are rounded to nearest even number. | High | Unbiased |
Floor | Rounds to the nearest representable number in the direction of negative infinity. Equivalent to two's complement truncation. | N/A | Low | Large negative |
Nearest | Rounds to the nearest representable number. | Ties are rounded to the closest representable number in the direction of positive infinity. | Moderate | Small positive |
Round | Rounds to the nearest representable number. |
| High |
|
Simplest (Simulink® only) | Automatically chooses between Floor and
Zero to produce generated code that is as
efficient as possible. | N/A | Low | Depends on the operation |
Zero | Rounds to the nearest representable number in the direction of zero. | N/A | Low |
|
These rounding modes are available for fixed-point Simulink blocks in the Integer rounding mode drop-down menu of the Block Parameters dialog box.
Choosing a Rounding Mode for Diagnostic Purposes
Rounding toward ceiling and rounding toward floor are sometimes useful for diagnostic purposes. For example, after a series of arithmetic operations, you may not know the exact answer because of word length limitations, which introduce rounding. If every operation in the series is performed twice, once rounding to positive infinity and once rounding to negative infinity, you obtain an upper limit and a lower limit on the correct answer. You can then decide if the result is sufficiently accurate or if additional analysis is necessary.