Scaled Doubles

What Are Scaled Doubles?

Scaled doubles are a hybrid between floating-point and fixed-point numbers. The Fixed-Point Designer™ software stores them as doubles with the scaling, sign, and word length information retained. For example, the storage container for a fixed-point data type sfix16_En14 is int16. The storage container of the equivalent scaled doubles data type, flts16_En14 is floating-point double. For details of the fixed-point scaling notation, see Fixed-Point Data Type and Scaling Notation. The Fixed-Point Designer software applies the scaling information to the stored floating-point double to obtain the real-world value. Storing the value in a double almost always eliminates overflow and precision issues.

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 are storing 0.75001 degrees Celsius in a data type sfix16_En13. For this data type:

  • The slope, S=213.

  • The bias, B=0.

Using the scaling equation VV~=SQ+B, where V is the real-world value and Q is the stored value.

  • B=0.

  • V~=SQ=213Q=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, so 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.

When to Use Scaled Doubles

The Fixed-Point Tool enables you to perform various data type overrides on fixed-point signals in your simulations. Use scaled doubles to override the fixed-point data types and scaling using double-precision numbers to avoid quantization effects. Overriding the fixed-point data types provides a floating-point benchmark that represents the ideal output.

Scaled doubles are useful for:

  • Testing and debugging

  • Detecting overflows

  • Applying data type overrides to individual subsystems

    If you apply a data type override to subsystems in your model rather than to the whole model, Scaled doubles provide the information that the fixed-point portions of the model need for consistent data type propagation.