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 '' AS five, * FROM FLOAT8_TBL;
124 ------+----------------------
128 | 1.2345678901234e+200
129 | 1.2345678901234e-200
132 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <> '1004.3';
134 ------+----------------------
137 | 1.2345678901234e+200
138 | 1.2345678901234e-200
141 SELECT '' AS one, f.* FROM FLOAT8_TBL f WHERE f.f1 = '1004.3';
147 SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE '1004.3' > f.f1;
149 -------+----------------------
152 | 1.2345678901234e-200
155 SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE f.f1 < '1004.3';
157 -------+----------------------
160 | 1.2345678901234e-200
163 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE '1004.3' >= f.f1;
165 ------+----------------------
169 | 1.2345678901234e-200
172 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <= '1004.3';
174 ------+----------------------
178 | 1.2345678901234e-200
181 SELECT '' AS three, f.f1, f.f1 * '-10' AS x
185 -------+----------------------+-----------------------
187 | 1.2345678901234e+200 | -1.2345678901234e+201
188 | 1.2345678901234e-200 | -1.2345678901234e-199
191 SELECT '' AS three, f.f1, f.f1 + '-10' AS x
195 -------+----------------------+----------------------
197 | 1.2345678901234e+200 | 1.2345678901234e+200
198 | 1.2345678901234e-200 | -10
201 SELECT '' AS three, f.f1, f.f1 / '-10' AS x
205 -------+----------------------+-----------------------
207 | 1.2345678901234e+200 | -1.2345678901234e+199
208 | 1.2345678901234e-200 | -1.2345678901234e-201
211 SELECT '' AS three, f.f1, f.f1 - '-10' AS x
215 -------+----------------------+----------------------
217 | 1.2345678901234e+200 | 1.2345678901234e+200
218 | 1.2345678901234e-200 | 10
221 SELECT '' AS one, f.f1 ^ '2.0' AS square_f1
222 FROM FLOAT8_TBL f where f.f1 = '1004.3';
229 SELECT '' AS five, f.f1, @f.f1 AS abs_f1
232 ------+----------------------+----------------------
236 | 1.2345678901234e+200 | 1.2345678901234e+200
237 | 1.2345678901234e-200 | 1.2345678901234e-200
241 SELECT '' AS five, f.f1, trunc(f.f1) AS trunc_f1
244 ------+----------------------+----------------------
248 | 1.2345678901234e+200 | 1.2345678901234e+200
249 | 1.2345678901234e-200 | 0
253 SELECT '' AS five, f.f1, round(f.f1) AS round_f1
256 ------+----------------------+----------------------
260 | 1.2345678901234e+200 | 1.2345678901234e+200
261 | 1.2345678901234e-200 | 0
265 select ceil(f1) as ceil_f1 from float8_tbl f;
267 ----------------------
275 select ceiling(f1) as ceiling_f1 from float8_tbl f;
277 ----------------------
286 select floor(f1) as floor_f1 from float8_tbl f;
288 ----------------------
297 select sign(f1) as sign_f1 from float8_tbl f;
308 SELECT sqrt(float8 '64') AS eight;
314 SELECT |/ float8 '64' AS eight;
320 SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
324 -------+----------------------+-----------------------
325 | 1004.3 | 31.6906926399535
326 | 1.2345678901234e+200 | 1.11111110611109e+100
327 | 1.2345678901234e-200 | 1.11111110611109e-100
331 SELECT power(float8 '144', float8 '0.5');
337 -- take exp of ln(f.f1)
338 SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
341 three | f1 | exp_ln_f1
342 -------+----------------------+-----------------------
344 | 1.2345678901234e+200 | 1.23456789012338e+200
345 | 1.2345678901234e-200 | 1.23456789012339e-200
349 SELECT ||/ float8 '27' AS three;
355 SELECT '' AS five, f.f1, ||/f.f1 AS cbrt_f1 FROM FLOAT8_TBL f;
357 ------+----------------------+----------------------
359 | 1004.3 | 10.014312837827
360 | -34.84 | -3.26607421344208
361 | 1.2345678901234e+200 | 4.97933859234765e+66
362 | 1.2345678901234e-200 | 2.3112042409018e-67
365 SELECT '' AS five, * FROM FLOAT8_TBL;
367 ------+----------------------
371 | 1.2345678901234e+200
372 | 1.2345678901234e-200
376 SET f1 = FLOAT8_TBL.f1 * '-1'
377 WHERE FLOAT8_TBL.f1 > '0.0';
378 SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
379 ERROR: value out of range: overflow
380 SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
381 ERROR: value out of range: overflow
382 SELECT 0 ^ 0 + 0 ^ 1 + 0 ^ 0.0 + 0 ^ 0.5;
388 SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
389 ERROR: cannot take logarithm of zero
390 SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
391 ERROR: cannot take logarithm of a negative number
392 SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
393 ERROR: value out of range: underflow
394 SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
395 ERROR: division by zero
396 SELECT '' AS five, * FROM FLOAT8_TBL;
398 ------+-----------------------
402 | -1.2345678901234e+200
403 | -1.2345678901234e-200
406 -- test for over- and underflow
407 INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
408 ERROR: "10e400" is out of range for type double precision
409 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
411 INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
412 ERROR: "-10e400" is out of range for type double precision
413 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
415 INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
416 ERROR: "10e-400" is out of range for type double precision
417 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
419 INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
420 ERROR: "-10e-400" is out of range for type double precision
421 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
423 -- maintain external table consistency across platforms
424 -- delete all values and reinsert well-behaved ones
425 DELETE FROM FLOAT8_TBL;
426 INSERT INTO FLOAT8_TBL(f1) VALUES ('0.0');
427 INSERT INTO FLOAT8_TBL(f1) VALUES ('-34.84');
428 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1004.30');
429 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e+200');
430 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e-200');
431 SELECT '' AS five, * FROM FLOAT8_TBL;
433 ------+-----------------------
437 | -1.2345678901234e+200
438 | -1.2345678901234e-200