TOTALORDER scalar function

The TOTALORDER function returns an ordering for DECFLOAT values. The TOTALORDER function returns a small integer value that indicates how expression1 compares with expression2.

Read syntax diagramSkip visual syntax diagramTOTALORDER( expression1, expression2)

The schema is SYSIBM.

expression1
An expression that returns a built-in DECFLOAT value.

The argument can also be a character string or graphic string data type. The string input is implicitly cast to a numeric value of DECFLOAT(34).

expression2
An expression that returns a built-in DECFLOAT value.

The argument can also be a character string or graphic string data type. The string input is implicitly cast to a numeric value of DECFLOAT(34).

Numeric comparison is exact, and the result is determined for finite operands as if range and precision are unlimited. An overflow or underflow conditions cannot occur.

If one value is DECFLOAT(16) and the other is DECFLOAT(34), the DECFLOAT(16) value is converted to DECFLOAT(34) before the comparison is made.

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

  • -1 if the first argument is lower in order compared to the second.
  • 0 if both arguments have the same order.
  • 1 if the first argument is higher in order compared to the second.
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 a SMALLINT value.

The result can be null; if any 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