4 CREATE TABLE FLOAT8_TBL(f1 float8);
5 INSERT INTO FLOAT8_TBL(f1) VALUES (' 0.0 ');
6 INSERT INTO FLOAT8_TBL(f1) VALUES ('1004.30 ');
7 INSERT INTO FLOAT8_TBL(f1) VALUES (' -34.84');
8 INSERT INTO FLOAT8_TBL(f1) VALUES ('1.2345678901234e+200');
9 INSERT INTO FLOAT8_TBL(f1) VALUES ('1.2345678901234e-200');
10 -- test for underflow and overflow handling
11 SELECT '10e400'::float8;
12 ERROR: "10e400" is out of range for type double precision
13 LINE 1: SELECT '10e400'::float8;
15 SELECT '-10e400'::float8;
16 ERROR: "-10e400" is out of range for type double precision
17 LINE 1: SELECT '-10e400'::float8;
19 SELECT '10e-400'::float8;
20 ERROR: "10e-400" is out of range for type double precision
21 LINE 1: SELECT '10e-400'::float8;
23 SELECT '-10e-400'::float8;
24 ERROR: "-10e-400" is out of range for type double precision
25 LINE 1: SELECT '-10e-400'::float8;
28 INSERT INTO FLOAT8_TBL(f1) VALUES ('');
29 ERROR: invalid input syntax for type double precision: ""
30 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('');
32 INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
33 ERROR: invalid input syntax for type double precision: " "
34 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
36 INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
37 ERROR: invalid input syntax for type double precision: "xyz"
38 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
40 INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
41 ERROR: invalid input syntax for type double precision: "5.0.0"
42 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
44 INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
45 ERROR: invalid input syntax for type double precision: "5 . 0"
46 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
48 INSERT INTO FLOAT8_TBL(f1) VALUES ('5. 0');
49 ERROR: invalid input syntax for type double precision: "5. 0"
50 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5. 0');
52 INSERT INTO FLOAT8_TBL(f1) VALUES (' - 3');
53 ERROR: invalid input syntax for type double precision: " - 3"
54 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES (' - 3');
56 INSERT INTO FLOAT8_TBL(f1) VALUES ('123 5');
57 ERROR: invalid input syntax for type double precision: "123 5"
58 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('123 5');
73 SELECT ' NAN '::float8;
79 SELECT 'infinity'::float8;
85 SELECT ' -INFINiTY '::float8;
92 SELECT 'N A N'::float8;
93 ERROR: invalid input syntax for type double precision: "N A N"
94 LINE 1: SELECT 'N A N'::float8;
96 SELECT 'NaN x'::float8;
97 ERROR: invalid input syntax for type double precision: "NaN x"
98 LINE 1: SELECT 'NaN x'::float8;
100 SELECT ' INFINITY x'::float8;
101 ERROR: invalid input syntax for type double precision: " INFINITY x"
102 LINE 1: SELECT ' INFINITY x'::float8;
104 SELECT 'Infinity'::float8 + 100.0;
110 SELECT 'Infinity'::float8 / 'Infinity'::float8;
116 SELECT 'nan'::float8 / 'nan'::float8;
122 SELECT 'nan'::numeric::float8;
128 SELECT '' AS five, * FROM FLOAT8_TBL;
130 ------+----------------------
134 | 1.2345678901234e+200
135 | 1.2345678901234e-200
138 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <> '1004.3';
140 ------+----------------------
143 | 1.2345678901234e+200
144 | 1.2345678901234e-200
147 SELECT '' AS one, f.* FROM FLOAT8_TBL f WHERE f.f1 = '1004.3';
153 SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE '1004.3' > f.f1;
155 -------+----------------------
158 | 1.2345678901234e-200
161 SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE f.f1 < '1004.3';
163 -------+----------------------
166 | 1.2345678901234e-200
169 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE '1004.3' >= f.f1;
171 ------+----------------------
175 | 1.2345678901234e-200
178 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <= '1004.3';
180 ------+----------------------
184 | 1.2345678901234e-200
187 SELECT '' AS three, f.f1, f.f1 * '-10' AS x
191 -------+----------------------+-----------------------
193 | 1.2345678901234e+200 | -1.2345678901234e+201
194 | 1.2345678901234e-200 | -1.2345678901234e-199
197 SELECT '' AS three, f.f1, f.f1 + '-10' AS x
201 -------+----------------------+----------------------
203 | 1.2345678901234e+200 | 1.2345678901234e+200
204 | 1.2345678901234e-200 | -10
207 SELECT '' AS three, f.f1, f.f1 / '-10' AS x
211 -------+----------------------+-----------------------
213 | 1.2345678901234e+200 | -1.2345678901234e+199
214 | 1.2345678901234e-200 | -1.2345678901234e-201
217 SELECT '' AS three, f.f1, f.f1 - '-10' AS x
221 -------+----------------------+----------------------
223 | 1.2345678901234e+200 | 1.2345678901234e+200
224 | 1.2345678901234e-200 | 10
227 SELECT '' AS one, f.f1 ^ '2.0' AS square_f1
228 FROM FLOAT8_TBL f where f.f1 = '1004.3';
235 SELECT '' AS five, f.f1, @f.f1 AS abs_f1
238 ------+----------------------+----------------------
242 | 1.2345678901234e+200 | 1.2345678901234e+200
243 | 1.2345678901234e-200 | 1.2345678901234e-200
247 SELECT '' AS five, f.f1, trunc(f.f1) AS trunc_f1
250 ------+----------------------+----------------------
254 | 1.2345678901234e+200 | 1.2345678901234e+200
255 | 1.2345678901234e-200 | 0
259 SELECT '' AS five, f.f1, round(f.f1) AS round_f1
262 ------+----------------------+----------------------
266 | 1.2345678901234e+200 | 1.2345678901234e+200
267 | 1.2345678901234e-200 | 0
271 select ceil(f1) as ceil_f1 from float8_tbl f;
273 ----------------------
281 select ceiling(f1) as ceiling_f1 from float8_tbl f;
283 ----------------------
292 select floor(f1) as floor_f1 from float8_tbl f;
294 ----------------------
303 select sign(f1) as sign_f1 from float8_tbl f;
314 SELECT sqrt(float8 '64') AS eight;
320 SELECT |/ float8 '64' AS eight;
326 SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
330 -------+----------------------+-----------------------
331 | 1004.3 | 31.6906926399535
332 | 1.2345678901234e+200 | 1.11111110611109e+100
333 | 1.2345678901234e-200 | 1.11111110611109e-100
337 SELECT power(float8 '144', float8 '0.5');
343 -- take exp of ln(f.f1)
344 SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
347 three | f1 | exp_ln_f1
348 -------+----------------------+-----------------------
350 | 1.2345678901234e+200 | 1.23456789012338e+200
351 | 1.2345678901234e-200 | 1.23456789012339e-200
355 SELECT ||/ float8 '27' AS three;
361 SELECT '' AS five, f.f1, ||/f.f1 AS cbrt_f1 FROM FLOAT8_TBL f;
363 ------+----------------------+----------------------
365 | 1004.3 | 10.014312837827
366 | -34.84 | -3.26607421344208
367 | 1.2345678901234e+200 | 4.97933859234765e+66
368 | 1.2345678901234e-200 | 2.3112042409018e-67
371 SELECT '' AS five, * FROM FLOAT8_TBL;
373 ------+----------------------
377 | 1.2345678901234e+200
378 | 1.2345678901234e-200
382 SET f1 = FLOAT8_TBL.f1 * '-1'
383 WHERE FLOAT8_TBL.f1 > '0.0';
384 SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
385 ERROR: value out of range: overflow
386 SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
387 ERROR: value out of range: overflow
388 SELECT 0 ^ 0 + 0 ^ 1 + 0 ^ 0.0 + 0 ^ 0.5;
394 SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
395 ERROR: cannot take logarithm of zero
396 SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
397 ERROR: cannot take logarithm of a negative number
398 SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
399 ERROR: value out of range: underflow
400 SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
401 ERROR: division by zero
402 SELECT '' AS five, * FROM FLOAT8_TBL;
404 ------+-----------------------
408 | -1.2345678901234e+200
409 | -1.2345678901234e-200
412 -- test for over- and underflow
413 INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
414 ERROR: "10e400" is out of range for type double precision
415 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
417 INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
418 ERROR: "-10e400" is out of range for type double precision
419 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
421 INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
422 ERROR: "10e-400" is out of range for type double precision
423 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
425 INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
426 ERROR: "-10e-400" is out of range for type double precision
427 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
429 -- maintain external table consistency across platforms
430 -- delete all values and reinsert well-behaved ones
431 DELETE FROM FLOAT8_TBL;
432 INSERT INTO FLOAT8_TBL(f1) VALUES ('0.0');
433 INSERT INTO FLOAT8_TBL(f1) VALUES ('-34.84');
434 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1004.30');
435 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e+200');
436 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e-200');
437 SELECT '' AS five, * FROM FLOAT8_TBL;
439 ------+-----------------------
443 | -1.2345678901234e+200
444 | -1.2345678901234e-200