Main Content

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: Ε(θ^θ)?

    • Ε(θ^θ)<0 — The rounding method introduces a negative bias.

    • Ε(θ^θ)=0 — The rounding method is unbiased.

    • Ε(θ^θ)>0 — 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 ModeDescriptionTie HandlingCostBias
CeilingRounds to the nearest representable number in the direction of positive infinity.N/ALowLarge positive
ConvergentRounds to the nearest representable number.Ties are rounded to nearest even number.HighUnbiased
FloorRounds to the nearest representable number in the direction of negative infinity. Equivalent to two's complement truncation.N/ALowLarge negative
NearestRounds to the nearest representable number.Ties are rounded to the closest representable number in the direction of positive infinity.ModerateSmall positive
RoundRounds to the nearest representable number.
  • For positive numbers, ties are rounded to the nearest representable number in the direction of positive infinity.

  • For negative numbers, ties are rounded to the nearest representable number in the direction of negative infinity.

High
  • Small negative for negative samples

  • Unbiased for samples with evenly distributed positive and negative values

  • Small positive for positive samples

Simplest
(Simulink® only)
Automatically chooses between Floor and Zero to produce generated code that is as efficient as possible.N/ALowDepends on the operation
ZeroRounds to the nearest representable number in the direction of zero.N/ALow
  • Large positive for negative samples

  • Unbiased for samples with evenly distributed positive and negative values

  • Large negative for positive samples

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.

Related Topics