What is the Difference between Scaled Double and Double Data Types?
The storage container for both the scaled double and double data types is
floating-point double. Therefore both data type override settings,
Double and Scaled double, provide the range and
precision advantages of floating-point doubles. Scaled doubles retain the information
about the specified data type and scaling, but doubles do not retain this information.
Because scaled doubles retain the information about the specified scaling, they can also
be used for overflow detection.
Consider an example where you want to store a value of 0.75001
degrees Celsius in a data type sfix16_En13. For this data type:
The slope is S=2−13.
The bias is B=0.
Using the scaling equation V≈V~=SQ+B, where V is the real-world value and
Q is the stored integer value:
B=0.
V~=SQ=2−13Q=0.75001.
Because the storage container of the data type sfix16_En13 is 16
bits, the stored integer Q can only be represented as an integer within
these 16 bits. Therefore, the ideal value of Q is quantized to
6144, causing precision loss.
If you override the data type sfix16_En13 with
Double, the data type changes to Double and you
lose the information about the scaling. The stored-value equals the real-world value
0.75001.
If you override the data type sfix16_En13 with Scaled
Double, the data type changes to flts16_En13. The scaling
is still given by _En13 and is identical to that of the original data
type. The only difference is the storage container used to hold the stored value which is
now double so the stored-value is 6144.08192. This
example shows one advantage of using scaled doubles: the virtual elimination of
quantization errors.