TOTALORDER

The TOTALORDER function returns an ordering for DECFLOAT values.

TOTALORDER(expression-1,expression-2)

The TOTALORDER function returns a small integer value that indicates how expression-1 compares with expression-2.

expression-1
An expression that returns a value of any built-in numeric, character-string, or graphic-string data type. If the argument is not DECFLOAT(34), it is logically converted to DECFLOAT(34) for processing.
expression-2
An expression that returns a value of any built-in numeric, character-string, or graphic-string data type. If the argument is not DECFLOAT(34), it is logically converted to DECFLOAT(34) for processing.

Numeric comparison is exact, and the result is determined for finite operands as if range and precision were unlimited. Overflow or underflow cannot occur.

TOTALORDER determines ordering based on the total order predicate rules of IEEE 754R, with the following result:

The ordering of the special values and finite numbers is as follows:

-NAN<-SNAN<-INFINITY<-0.10<-0.100<-0<0<0.100<0.10<INFINITY<SNAN<NAN

The result of the function is SMALLINT. If either argument can be null, the result can be null; if either argument is null, the result is the null value.

Examples

The following examples show the use of the TOTALORDER function to compare decimal floating-point values:

    TOTALORDER(-INFINITY, -INFINITY)                  =    0
    TOTALORDER(DECFLOAT(-1.0), DECFLOAT(-1.0))        =    0
    TOTALORDER(DECFLOAT(-1.0), DECFLOAT(-1.00))       =   -1
    TOTALORDER(DECFLOAT(-1.0), DECFLOAT(-0.5))        =   -1
    TOTALORDER(DECFLOAT(-1.0), DECFLOAT(0.5))         =   -1
    TOTALORDER(DECFLOAT(-1.0), INFINITY)              =   -1
    TOTALORDER(DECFLOAT(-1.0), SNAN)                  =   -1
    TOTALORDER(DECFLOAT(-1.0), NAN)                   =   -1
    TOTALORDER(NAN, DECFLOAT(-1.0))                   =    1
    TOTALORDER(-NAN, -NAN)                            =    0
    TOTALORDER(-SNAN, -SNAN)                          =    0
    TOTALORDER(NAN, NAN)                              =    0
    TOTALORDER(SNAN, SNAN)                            =    0