DECFLOAT (Firebird 4.0)

Source: https://github.com/FirebirdSQL/firebird/blob/master/doc/sql.extensions/README.data_types

Function

DB2-compliant numeric type. DECFLOAT precisely (unlike FLOAT or DOUBLE PRECISION that provide binary approximation) stores decimal values being therefore ideal choice for business applications. Firebird according to IEEE standard has both 16- and 34-digit decimal float encodings. All intermediate calculations are performed with 34-digit values.

Author Alex Peshkoff peshkoff@mail.ru

Syntax rules

  DECFLOAT
  DECFLOAT(16)
  DECFLOAT(34)

Storage

64-bit / 128-bit, format according to IEEE 754 Decimal64/Decimal128

Example(s)

  1. DECLARE VARIABLE VAR1 DECFLOAT(34);
  2. CREATE TABLE TABLE1 (FIELD1 DECFLOAT(16));

Note(s)

1. If no precision has been specified in the type declaration, the precision is 34.

2. A number of standard functions can be used with DECFLOAT datatype. It is:

ABS, CEILING, EXP, FLOOR, LN, LOG, LOG10, POWER, SIGN, SQRT.

Agregate functions SUM, AVG, MAX and MIN also work with DECFLOAT data. All statistics aggregates (like but not limited to STDDEV or CORR) work with DECFLOAT data.

3. Firebird supports four functions, specially designed to support DECFLOAT data:

              0 - values are equal
              1 - first value is less than second
              2 - first value is greater than second
              3 - values unordered (i.e. one or both is NAN / SNAN)

Unlike comparison operators ('<', '=', '>', etc.) comparison is exact - i.e. COMPARE_DECFLOAT(2.17, 2.170) returns 2, not 0.

  1. 1 - first value is less than second

0 - values are equal

               1 - first value is greater than second

DECFLOAT values are ordered as follows:

  1. nan < -snan < -inf < -0.1 < -0.10 < -0 < 0 < 0.10 < 0.1 < inf < snan < nan

4. Firebird supports new session control operator SET DECFLOAT. It has following forms:

5. The length of DECFLOAT literals are limited to 1024 characters. For longer values, you will need to use the scientific notation. For example, the 0.0<1020 zeroes>11 cannot be used as a literal, instead you can use the equivalent in scientific notation: 1.1E-1022. Similarly 10<1022 zeroes>0 can be presented as 1.0E1024.