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;
25 SELECT '-10e-400'::float8;
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 (' ');
37 ERROR: invalid input syntax for type double precision: " "
38 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
40 INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
41 ERROR: invalid input syntax for type double precision: "xyz"
42 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
44 INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
45 ERROR: invalid input syntax for type double precision: "5.0.0"
46 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.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 ('5. 0');
53 ERROR: invalid input syntax for type double precision: "5. 0"
54 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5. 0');
56 INSERT INTO FLOAT8_TBL(f1) VALUES (' - 3');
57 ERROR: invalid input syntax for type double precision: " - 3"
58 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES (' - 3');
60 INSERT INTO FLOAT8_TBL(f1) VALUES ('123 5');
61 ERROR: invalid input syntax for type double precision: "123 5"
62 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('123 5');
77 SELECT ' NAN '::float8;
83 SELECT 'infinity'::float8;
89 SELECT ' -INFINiTY '::float8;
96 SELECT 'N A N'::float8;
97 ERROR: invalid input syntax for type double precision: "N A N"
98 LINE 1: SELECT 'N A N'::float8;
100 SELECT 'NaN x'::float8;
101 ERROR: invalid input syntax for type double precision: "NaN x"
102 LINE 1: SELECT 'NaN x'::float8;
104 SELECT ' INFINITY x'::float8;
105 ERROR: invalid input syntax for type double precision: " INFINITY x"
106 LINE 1: SELECT ' INFINITY x'::float8;
108 SELECT 'Infinity'::float8 + 100.0;
114 SELECT 'Infinity'::float8 / 'Infinity'::float8;
120 SELECT 'nan'::float8 / 'nan'::float8;
126 SELECT 'nan'::numeric::float8;
132 SELECT '' AS five, * FROM FLOAT8_TBL;
134 ------+----------------------
138 | 1.2345678901234e+200
139 | 1.2345678901234e-200
142 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <> '1004.3';
144 ------+----------------------
147 | 1.2345678901234e+200
148 | 1.2345678901234e-200
151 SELECT '' AS one, f.* FROM FLOAT8_TBL f WHERE f.f1 = '1004.3';
157 SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE '1004.3' > f.f1;
159 -------+----------------------
162 | 1.2345678901234e-200
165 SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE f.f1 < '1004.3';
167 -------+----------------------
170 | 1.2345678901234e-200
173 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE '1004.3' >= f.f1;
175 ------+----------------------
179 | 1.2345678901234e-200
182 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <= '1004.3';
184 ------+----------------------
188 | 1.2345678901234e-200
191 SELECT '' AS three, f.f1, f.f1 * '-10' AS x
195 -------+----------------------+-----------------------
197 | 1.2345678901234e+200 | -1.2345678901234e+201
198 | 1.2345678901234e-200 | -1.2345678901234e-199
201 SELECT '' AS three, f.f1, f.f1 + '-10' AS x
205 -------+----------------------+----------------------
207 | 1.2345678901234e+200 | 1.2345678901234e+200
208 | 1.2345678901234e-200 | -10
211 SELECT '' AS three, f.f1, f.f1 / '-10' AS x
215 -------+----------------------+-----------------------
217 | 1.2345678901234e+200 | -1.2345678901234e+199
218 | 1.2345678901234e-200 | -1.2345678901234e-201
221 SELECT '' AS three, f.f1, f.f1 - '-10' AS x
225 -------+----------------------+----------------------
227 | 1.2345678901234e+200 | 1.2345678901234e+200
228 | 1.2345678901234e-200 | 10
231 SELECT '' AS one, f.f1 ^ '2.0' AS square_f1
232 FROM FLOAT8_TBL f where f.f1 = '1004.3';
239 SELECT '' AS five, f.f1, @f.f1 AS abs_f1
242 ------+----------------------+----------------------
246 | 1.2345678901234e+200 | 1.2345678901234e+200
247 | 1.2345678901234e-200 | 1.2345678901234e-200
251 SELECT '' AS five, f.f1, trunc(f.f1) AS trunc_f1
254 ------+----------------------+----------------------
258 | 1.2345678901234e+200 | 1.2345678901234e+200
259 | 1.2345678901234e-200 | 0
263 SELECT '' AS five, f.f1, round(f.f1) AS round_f1
266 ------+----------------------+----------------------
270 | 1.2345678901234e+200 | 1.2345678901234e+200
271 | 1.2345678901234e-200 | 0
275 select ceil(f1) as ceil_f1 from float8_tbl f;
277 ----------------------
285 select ceiling(f1) as ceiling_f1 from float8_tbl f;
287 ----------------------
296 select floor(f1) as floor_f1 from float8_tbl f;
298 ----------------------
307 select sign(f1) as sign_f1 from float8_tbl f;
318 SELECT sqrt(float8 '64') AS eight;
324 SELECT |/ float8 '64' AS eight;
330 SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
334 -------+----------------------+-----------------------
335 | 1004.3 | 31.6906926399535
336 | 1.2345678901234e+200 | 1.11111110611109e+100
337 | 1.2345678901234e-200 | 1.11111110611109e-100
341 SELECT power(float8 '144', float8 '0.5');
347 -- take exp of ln(f.f1)
348 SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
351 three | f1 | exp_ln_f1
352 -------+----------------------+-----------------------
354 | 1.2345678901234e+200 | 1.23456789012338e+200
355 | 1.2345678901234e-200 | 1.23456789012339e-200
359 SELECT ||/ float8 '27' AS three;
365 SELECT '' AS five, f.f1, ||/f.f1 AS cbrt_f1 FROM FLOAT8_TBL f;
367 ------+----------------------+----------------------
369 | 1004.3 | 10.014312837827
370 | -34.84 | -3.26607421344208
371 | 1.2345678901234e+200 | 4.97933859234765e+66
372 | 1.2345678901234e-200 | 2.3112042409018e-67
375 SELECT '' AS five, * FROM FLOAT8_TBL;
377 ------+----------------------
381 | 1.2345678901234e+200
382 | 1.2345678901234e-200
386 SET f1 = FLOAT8_TBL.f1 * '-1'
387 WHERE FLOAT8_TBL.f1 > '0.0';
388 SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
389 ERROR: value out of range: overflow
390 SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
391 ERROR: value out of range: overflow
392 SELECT 0 ^ 0 + 0 ^ 1 + 0 ^ 0.0 + 0 ^ 0.5;
398 SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
399 ERROR: cannot take logarithm of zero
400 SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
401 ERROR: cannot take logarithm of a negative number
402 SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
403 ERROR: value out of range: underflow
404 SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
405 ERROR: division by zero
406 SELECT '' AS five, * FROM FLOAT8_TBL;
408 ------+-----------------------
412 | -1.2345678901234e+200
413 | -1.2345678901234e-200
416 -- test for over- and underflow
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 ('-10e400');
422 ERROR: "-10e400" is out of range for type double precision
423 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
425 INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
426 INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
427 -- maintain external table consistency across platforms
428 -- delete all values and reinsert well-behaved ones
429 DELETE FROM FLOAT8_TBL;
430 INSERT INTO FLOAT8_TBL(f1) VALUES ('0.0');
431 INSERT INTO FLOAT8_TBL(f1) VALUES ('-34.84');
432 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1004.30');
433 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e+200');
434 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e-200');
435 SELECT '' AS five, * FROM FLOAT8_TBL;
437 ------+-----------------------
441 | -1.2345678901234e+200
442 | -1.2345678901234e-200