It's just like scientific notation
is the short answer to "Why FractionLength can be bigger than WordLength?".
The long answer is the following.
The concept of a binary-point is very useful for initial understanding of fixed-point types. Similarly, the concept of a decimal-point is useful for understanding values beyond integers. But using decimal-points becomes very cumbersome for very big or very small numbers. To make it easy to represent very big or very small values, scientific notation is super valuable.
verySmallNumber = 3e-200;
In essence, this notation breaks the value into two parts, a mantissa and an integer exponent for the given base.
Y = mantissa .* 10.^exponent
Fixed-point follows the same concept except that
- base is 2
- mantissa must be an integer
- exponent is fixed, i.e. it is part of the variables type and does not change for the life of the variable
Y = intMantissa .* 2^FixedExponent
Since FractionLength = -FixedExponent, we can also write this as follows.
Y = intMantissa .* 2^-FractionLength
A nice thing about fi is that we can let it figure out the scaling that gives the best precision for a constant.
verySmallNumberFi = fi( 3e-200, 0, 8 )
veryBigNumberFi = fi( 7e123, 0, 8 )
Notice the very big positive and negative FractionLengths of 670 and -404 that are produced.
Fi has approximated the original double values using 8-bit unsigned integer mantissas.
147 * 2^-670
169 * 2^404
It's just scientific notation in base 2.