8.10. Special Functions for DECFLOAT
8.10.1. COMPARE_DECFLOAT()
Compares two DECFLOAT values to be equal, different or unordered
Result typeSMALLINT
Syntax
COMPARE_DECFLOAT (decfloat1, decfloat2)
COMPARE_DECFLOAT Function Parameters| Parameter | Description |
|---|---|
decfloatn | Value or expression of type |
The result is a SMALLINT value, as follows:
|
|
Values are equal |
|
|
First value is less than second |
|
|
First value is greater than second |
|
|
Values are unordered, i.e. one or both is |
Unlike the comparison operators (
, <
, =
, etc.), comparison is exact: >COMPARE_DECFLOAT(2.17, 2.170) returns 2 not 0.
See alsoSection 8.10.4, “TOTALORDER()”
8.10.2. NORMALIZE_DECFLOAT()
Returns the simplest, normalized form of a DECFLOAT
Result typeDECFLOAT
Syntax
NORMALIZE_DECFLOAT (decfloat_value)
NORMALIZE_DECFLOAT Function Parameters| Parameter | Description |
|---|---|
decfloat_value | Value or expression of type |
For any non-zero value, trailing zeroes are removed with appropriate correction of the exponent.
8.10.2.1. Examples of NORMALIZE_DECFLOAT
-- will return 12select normalize_decfloat(12.00)from rdb$database;-- will return 1.2E+2select normalize_decfloat(120)from rdb$database;
8.10.3. QUANTIZE()
Returns a value that is equal in value — except for rounding — to the first argument, but with the same exponent as the second argument
Result typeDECFLOAT
Syntax
QUANTIZE (decfloat_value, exp_value)
QUANTIZE Function Parameters| Parameter | Description |
|---|---|
decfloat_value | Value or expression to quantize;
needs to be of type |
exp_value | Value or expression to use for its exponent;
needs to be of type |
QUANTIZE returns a DECFLOAT value that is equal in value and sign (except for rounding) to decfloat_value, and that has an exponent equal to the exponent of exp_value.
The type of the return value is DECFLOAT(16) if both arguments are DECFLOAT(16), otherwise the result type is DECFLOAT(34).
The target exponent is the exponent used in the Decimal64 or Decimal128 storage format of DECFLOAT of exp_value.
This is not necessarily the same as the exponent displayed in tools like isql.
For example, the value 1.23E+2 is coefficient 123 and exponent 0, while 1.2 is coefficient 12 and exponent -1.
If the exponent of decfloat_value is greater than the one of exp_value, the coefficient of decfloat_value is multiplied by a power of ten, and its exponent decreased. If the exponent is smaller, then its coefficient is rounded using the current decfloat rounding mode, and its exponent is increased.
When it is not possible to achieve the target exponent because the coefficient would exceed the target precision (16 or 34 decimal digits), either a Decfloat float invalid operation
error is raised or NaN is returned (depending on the current decfloat traps configuration).
There are almost no restrictions on the exp_value.
However, in almost all usages, NaN/sNaN/Infinity will produce an exception (unless allowed by the current decfloat traps configuration), NULL will make the function return NULL, and so on.
8.10.3.1. Examples of QUANTIZE
select v, pic, quantize(v, pic) from examples;V PIC QUANTIZE====== ====== ========3.16 0.001 3.1603.16 0.01 3.163.16 0.1 3.23.16 1 33.16 1E+1 0E+1-0.1 1 -00 1E+5 0E+5316 0.1 316.0316 1 316316 1E+1 3.2E+2316 1E+2 3E+2
8.10.4. TOTALORDER()
Determines the total or linear order of its arguments
Result typeSMALLINT
Syntax
TOTALORDER (decfloat1, decfloat2)
TOTALORDER Function Parameters| Parameter | Description |
|---|---|
decfloatn | Value or expression of type |
TOTALORDER compares two DECFLOAT values including any special values.
The comparison is exact, and returns a SMALLINT, one of:
|
|
First value is less than second |
|
|
Values are equal |
|
|
First value is greater than second. |
For TOTALORDER comparisons, DECFLOAT values are ordered as follows:
-NaN < -sNaN < -INF < -0.1 < -0.10 < -0 < 0 < 0.10 < 0.1 < INF < sNaN < NaN