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.

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.

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: $${\rm E}\left(\widehat{\theta}-\theta \right)$$?

$${\rm E}\left(\widehat{\theta}-\theta \right)<0$$ — The rounding method introduces a negative bias.

$${\rm E}\left(\widehat{\theta}-\theta \right)=0$$ — The rounding method is unbiased.

$${\rm E}\left(\widehat{\theta}-\theta \right)>0$$ — 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.

To provide you with greater flexibility in the trade-off 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 | Possibility of Overflow |
---|---|---|---|---|---|

Ceiling | Rounds to the nearest representable number in the direction of positive infinity. | N/A | Low | Large positive | Yes |

Convergent | Rounds to the nearest representable number. | Ties are rounded to nearest even number. | High | Unbiased | Yes |

Floor | Rounds to the nearest representable number in the direction of negative infinity. Equivalent to two's complement truncation. | N/A | Low | Large negative | No |

Nearest | Rounds to the nearest representable number. | Ties are rounded to the closest representable number in the direction of positive infinity. | Moderate | Small positive | Yes |

Round | Rounds 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
| Yes |

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 | No |

Zero | Rounds to the nearest representable number in the direction of zero. | N/A | Low |
Large positive for negative samples Unbiased for samples with evenly distributed positive and negative values Large negative for positive samples
| No |

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-size 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.