Table Of Contents

Overflow in the Fixed-Point Data Type

Version:
    Last Modified: September 26, 2017

    Overflow in the fixed-point data type occurs when an input or computed result of an operation is greater than the maximum representable value or less than the minimum representable value of a given fixed-point configuration.

    Any time overflow occurs in your code, the overflow mode you select determines how the value is coerced. You specify the overflow mode in the Terminals section of the Item tab for an operator.

    The following table describes how overflow values are coerced in each overflow mode.

    Overflow Mode Behavior
    Saturate If the value is greater than the maximum value in the specified range of the output type, the value is coerced to the specified maximum. If the value is less than the minimum value in the specified range of the output type, the value is coerced to the specified minimum. Saturate is the default overflow mode.
    Wrap If the value is greater than the maximum value or less than the minimum value of the specified range of the output type, the most significant bits of the value are discarded until the value is within the range of the output type.

    Consider an example scenario where an input value exceeds the maximum representable value for an arbitrary configuration. Keep in mind that the Saturate and Wrap overflow modes affect the binary representation of fixed-point numbers. The binary representation of the decimal number 6.75 is 110.11. So the decimal number 6.75 requires at least a <3.2> unsigned fixed-point configuration to be represented exactly. If the decimal number 6.75 converts to a <2.2> unsigned fixed-point number, it exceeds the maximum value for the specified configuration. The following table demonstrates how behaviors for Saturate and Wrap differ when coercing the example decimal number 6.75.

    Example FXP Configuration Overflow Mode Input Value (Decimal) Input Value (Binary) Coerced Value (Binary) Coerced Value (Decimal)
    U4 <2.2> Saturate 6.75 110.11 11.11 3.75
    U4 <2.2> Wrap 6.75 110.11 10.11 2.75

    Using the Saturate overflow mode, the decimal number 6.75 is coerced to 3.75, the maximum value of an unsigned <2.2> fixed-point number. Using the Wrap overflow mode, the decimal number 6.75 is coerced to 2.75 by discarding an integer bit from the binary input value.


    Recently Viewed Topics