COMPARE_DECFLOAT

The COMPARE_DECFLOAT function returns an ordering for DECFLOAT values.

Read syntax diagramSkip visual syntax diagram
>>-COMPARE_DECFLOAT--(--expression-1--,--expression-2--)-------><

The COMPARE_DECFLOAT 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.

The first argument is compared with the second argument and the result is returned according to the following rules.

The result value is set as follows:

0 if the arguments are exactly equal.
1 if expression-1 is less than expression-2.
2 if expression-1 is greater than expression-2.
3 if the arguments are unordered.

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 demonstrate the values that will be returned when the function is used:

     COMPARE_DECFLOAT (DECFLOAT(2.17),  DECFLOAT(2.17))   =  0
     COMPARE_DECFLOAT (DECFLOAT(2.17),  DECFLOAT(2.170))  =  2
     COMPARE_DECFLOAT (DECFLOAT(2.170), DECFLOAT(2.17))   =  1
     COMPARE_DECFLOAT (DECFLOAT(2.17),  DECFLOAT(0.0))    =  2
     COMPARE_DECFLOAT (INFINITY,        INFINITY)         =  0
     COMPARE_DECFLOAT (INFINITY,        -INFINITY)        =  2
     COMPARE_DECFLOAT (DECFLOAT(-2),    INFINITY)         =  1
     COMPARE_DECFLOAT (NAN,             NAN)              =  3
     COMPARE_DECFLOAT (DECFLOAT(-0.1),  SNAN)             =  3