Determine the Range of Fixed-Point Numbers
R2026bFixed-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
where
Using the general [Slope Bias] encoding scheme described in Scaling, Range, and Precision, the approximate real-world value has the range
where
If the real-world value exceeds the limited range of the approximate value, then the accuracy of the representation can become significantly worse.
In MATLAB®, you can use the fixed.extractNumericType function to
extract the numeric type from an input, then use the lowerbound and
upperbound functions to determine the minimum and maximum
finite representable values of the numeric type. The input can be specified in a number
of ways, such as:
u = numerictype(1,8,3) u = fixdt(0,5,1) u = fi(pi,1,6) u = 'sfix4_En2' u = int8(4) u = pi u = half(3) u = 'single'
For this example, consider the input u = 'sfix5_En1'.
u = 'sfix5_En1';
nt = fixed.extractNumericType(u);
minFinRep = lowerbound(nt)
maxFinRep = upperbound(nt)minFinRep =
-8
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 5
FractionLength: 1
maxFinRep =
7.5000
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 5
FractionLength: 1Alternatively, use the range function to determine the minimum
and maximum finite representable values of the numeric type.
minMaxFinRep = range(nt)
minMaxFinRep =
-8.0000 7.5000
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 5
FractionLength: 1Use the stripscaling function to determine the minimum and
maximum stored integer values of the numeric type.
siMinMaxFinRep = stripscaling(range(nt))
siMinMaxFinRep =
-16 15
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 5
FractionLength: 0See Also
fixed.extractNumericType | lowerbound | upperbound | range | stripscaling