Skip to Main Content Skip to Search
Product Documentation

Precision and Range

Range

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 :

Overflow Handling

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.

Precision

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.

Rounding Methods

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:

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:

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 ModeCostBiasPossibility of Overflow
ceilCeilingLowLarge positiveYes
convergentConvergentHighUnbiasedYes
fixZeroLow
  • Large positive for negative samples

  • Unbiased for samples with evenly distributed positive and negative values

  • Large negative for positive samples

No
floorFloorLowLarge negativeNo
nearestNearestModerateSmall positiveYes
roundRoundHigh
  • Small negative for negative samples

  • Unbiased for samples with evenly distributed positive and negative values

  • Small positive for positive samples

Yes
N/ASimplest
(Simulink Fixed Point only)
LowDepends on the operationNo

  


Free Early Verification Kit

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