COMPARE_DECFLOAT

The COMPARE_DECFLOAT function returns a SMALLINT value that indicates whether the two arguments are equal or unordered, or whether one argument is greater than the other.

Read syntax diagram
>>-COMPARE_DECFLOAT(decfloat-expression1,decfloat-expression2)-><

The schema is SYSIBM.

decfloat-expression1
An expression that returns a DECFLOAT value.
decfloat-expression2
An expression that returns a DECFLOAT value.

decfloat-expression1 is compared with decfloat-expression2 and the result is returned according to the following rules:

  • If both arguments are finite, the comparison is algebraic and follows the procedure for DECFLOAT subtraction. If the different is exactly zero with either sign, the arguments are equal. If a nonzero difference is positive, the first argument is greater than the second argument. If a nonzero difference is negative, the first argument is less than the second.
  • Positive zero and negative zero compare as equal.
  • Positive infinity compares equal to positive infinity.
  • Positive infinity compares greater than any finite number.
  • Negative infinity compares equal to negative infinity.
  • Negative infinity compares less than any finite number.
  • Numeric comparison is exact and the result is determined for finite operands as if range and precision were unlimited. Overflow or underflow cannot occur.
  • If either argument is NaN or sNaN (positive or negative), the result is unordered.

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

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

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

One of the following values will be the result:
0
The arguments are exactly equal
1
decfloat-expression1 is less than decfloat-expression2
2
decfloat-expression1 is greater than decfloat-expression2
3
The arguments are unordered

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 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