Limitations on Range
Limitations on the range of a fixed-point word occur for the same reason as limitations on its precision. Namely, fixed-point words have limited size.
In binary arithmetic, a processor may need to take an n-bit fixed-point number and store it in m bits, where m ≠ n . If m < n, the range of the number has been reduced and an operation can produce an overflow condition. Some processors identify this condition as infinity or NaN. For other processors, especially digital signal processors (DSPs), the value saturates or wraps. If m > n, the range of the number has been extended. Extending the range of a word requires the inclusion of guard bits, which act to "guard" against potential overflow. In both cases, the range depends on the word's size and scaling.
The Fixed-Point Blockset supports saturation and wrapping for all fixed-point data types, while guard bits are supported only for fractional data types. As shown below, you can select saturation or wrapping with the Saturate to max or min when overflows occur check box, and you can specify guard bits with the Output data type parameter.
Saturation and Wrapping
Saturation and wrapping describe a particular way that some processors deal with overflow conditions. For example, Analog Device's ADSP-2100 family of processors supports either of these modes. If a register has a saturation mode of operation, then an overflow condition is set to the maximum positive or negative value allowed. Conversely, if a register has a wrapping mode of operation, an overflow condition is set to the appropriate value within the range of the representation.
Example: Saturation and Wrapping
Consider an 8-bit unsigned word with radix point-only scaling of 2-5. Suppose this data type must represent a sine wave that ranges from -4 to 4. For values between 0 and 4, the word can represent these numbers without regard to overflow. This is not the case with negative numbers. If overflows saturate, all negative values are set to zero, which is the smallest number representable by the data type. The saturation of overflows is shown below.
If overflows wrap, all negative values are set to the appropriate positive value. The wrapping of overflows is shown below.
For most control applications, saturation is the safer way of dealing with fixed-point overflow. However, some processor architectures allow automatic saturation by hardware. If hardware saturation is not available, then extra software is required resulting in larger, slower programs. This cost is justified in some designs - perhaps for safety reasons. Other designs accept wrapping to obtain the smallest, fastest software.
Guard Bits
You can eliminate the possibility of overflow by appending the appropriate number of guard bits to a binary word.
For a two's complement signed value, the guard bits are filled with either 0's or 1's depending on the value of the most significant bit (MSB). This is called sign extension. For example, consider a 4-bit two's complement number with value 1011. If this number is extended in range to 7 bits with sign extension, then the number becomes 1111101 and the value remains the same.
Guard bits are supported only for fractional data types. For both signed and unsigned fractionals, the guard bits lie to the left of the default radix point.
Example: Limitations on Range
Fixed-point variables have a limited range for the same reason they have limited precision - because digital systems represent numbers with a finite number of bits. As a general example, consider the case where an integer is represented as a fixed-point word of size ws. The range for signed and unsigned words is given by max(Q) - min(Q) where
Using the general slope/bias encoding scheme described in Scaling, the approximate real-world value has the range max(Ṽ) - min(Ṽ) where
If the real-world value exceeds the limited range of the approximate value, then the accuracy of the representation can become significantly worse.