COMPARE_DECFLOAT scalar function

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 diagramSkip visual syntax diagramCOMPARE_DECFLOAT(expression1 ,expression2)

The schema is SYSIBM.

expression1
An expression that returns a value of any built-in numeric data type. If the argument is not DECFLOAT(34), it is logically converted to DECFLOAT(34) for processing.
expression2
An expression that returns a value of any built-in numeric data type. If the argument is not DECFLOAT(34), it is logically converted to DECFLOAT(34) for processing.
The value of expression1 is compared with the value of 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 decimal floating-point subtraction. If the difference 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. The result is determined for finite operands as if range and precision were unlimited. No overflow or underflow condition can occur.
  • If either argument is NaN or sNaN (positive or negative), the result is unordered.
The result value is as follows:
  • 0 if the arguments are exactly equal
  • 1 if expression1 is less than expression2
  • 2 if expression1 is greater than expression2
  • 3 if the arguments are unordered

The result of the function is a SMALLINT value. 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 values that are returned by the COMPARE_DECFLOAT function, given a variety of input decimal floating-point values:
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