@@ -101,3 +101,82 @@ BINARY, VARBINARY, BINARY VARYING (FB 4.0)
101
101
2. Can be distinguished from text types by value 1 in RDB$FIELD_SUB_TYPE.
102
102
3. Character set is set to OCTETS for backward compatibility.
103
103
4. In API are similar to corresponding text types, getSubType() returns 0.
104
+
105
+
106
+ DECFLOAT (FB 4.0)
107
+ --------------
108
+
109
+ Function:
110
+ DB2-compliant numeric type. DECFLOAT precisely (unlike FLOAT or DOUBLE PRECISION that provide
111
+ binary approximation) stores decimal values being therefore ideal choice for business appli-
112
+ cations. Firebird according to IEEE standard has both 16- and 34-digit decimal float encodings.
113
+ All intermediate calculations are performed with 34-digit values.
114
+
115
+ Author:
116
+
117
+
118
+ Syntax rules:
119
+ DECFLOAT(16)
120
+ DECFLOAT(34)
121
+
122
+ Storage:
123
+ 64-bit / 128-bit, format according to IEEE 754.
124
+
125
+ Example(s):
126
+ 1. DECLARE VARIABLE VAR1 DECFLOAT(34);
127
+ 2. CREATE TABLE TABLE1 (FIELD1 DECFLOAT(16));
128
+
129
+ Note(s):
130
+ 1. A number of standard functions can be used with DECFLOAT datatype. It is:
131
+ ABS, CEILING, EXP, FLOOR, LN, LOG, LOG10, POWER, SIGN, SQRT.
132
+ Agregate functions SUM, AVG, MAX and MIN also work with DECFLOAT data.
133
+ All statistics aggregates (like but not limited to STDDEV or CORR) work with DECFLOAT data.
134
+
135
+ 2. Firebird supports four functions, specially designed to support DECFLOAT data:
136
+ - COMPARE_DECFLOAT - compares two DECFLOAT values to be equal, different or unordered.
137
+ Returns SMALLINT value which can be as follows:
138
+ 0 - values are equal
139
+ 1 - first value is less than second
140
+ 2 - first value is greater than second
141
+ 3 - values unordered (i.e. one or both is NAN / SNAN)
142
+ Unlike comparison operators ('<', '=', '>', etc.) comparison is exact - i.e.
143
+ COMPARE_DECFLOAT(2.17, 2.170) returns 2, not 0.
144
+ - NORMALIZE_DECFLOAT - has single DECFLOAT argument returned in it's simplest form. That
145
+ means that for any nonzero value trailing zero are removed with appropriate correction
146
+ of an exponent. For example NORMALIZE_DECFLOAT(12.00) returns 12 and
147
+ NORMALIZE_DECFLOAT(120) returns 1.2E+2.
148
+ - QUANTIZE - has two DECFLOAT arguments. The returned value is first argument scaled using
149
+ second value as a pattern. For example QUANTIZE(1234, 9.999) returns 1234.000.
150
+ - TOTALORDER - compares two DECFLOAT values including any special value. The comparison is
151
+ exact. Returns SMALLINT value which can be as follows:
152
+ -1 - first value is less than second
153
+ 0 - values are equal
154
+ 1 - first value is greater than second
155
+ DECFLOAT values are ordered as follows:
156
+ -nan < -snan < -inf < -0.1 < -0.10 < -0 < 0 < 0.10 < 0.1 < inf < snan < nan
157
+
158
+ 3. Firebird supports new session control operator SET DECFLOAT. It has following forms:
159
+ SET DECFLOAT ROUND <mode> - controls rounding mode used in operations with DECFLOAT
160
+ values. Valid modes are: CEILING (towards +infinity), UP (away from 0), HALF_UP
161
+ (to nearest, if equidistant - up), HALF_EVEN (to nearest, if equidistant - ensure
162
+ last digit in the result to be even), HALF_DOWN (to nearest, if equidistant - down),
163
+ DOWN (towards 0), FLOOR (towards -infinity), REROUND (up if digit to be rounded is
164
+ 0 or 5, down in other cases).
165
+
166
+ SET DECFLOAT TRAPS TO <comma-separated traps list - may be empty> - controls which
167
+ exceptional conditions cause a trap. Valid traps are: Division_by_zero, Inexact,
168
+ Invalid_operation, Overflow and Underflow. By default traps are set to:
169
+ Division_by_zero, Invalid_operation, Overflow, Underflow.
170
+
171
+ SET DECFLOAT BIND <bind-type> - controls how are DECFLOAT values represented in outer
172
+ world (i.e. in messages or in XSQLDA). Valid binding types are: NATIVE (use IEEE754
173
+ binary representation), CHAR/CHARACTER (use ASCII string), DOUBLE PRECISION (use
174
+ 8-byte FP representation - same as used for DOUBLE PRECISION fields) or BIGINT
175
+ with possible comma-separated SCALE clause (i.e. 'BIGINT, 3'). Various bindings
176
+ are useful if one plans to use DECFLOAT values with some old client not supporting
177
+ native format. One can choose between strings (ideal precision, but poor support
178
+ for further processing), floating point values (ideal support for further processing
179
+ but poor precision) or scaled integers (good support for further processing and
180
+ required precision but range of values is very limited). When using is a tool like
181
+ generic purporse GUI client choice of CHAR binding is OK in most cases.
182
+
0 commit comments