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 '' AS five, * FROM FLOAT8_TBL;
128 ------+----------------------
132 | 1.2345678901234e+200
133 | 1.2345678901234e-200
136 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <> '1004.3';
138 ------+----------------------
141 | 1.2345678901234e+200
142 | 1.2345678901234e-200
145 SELECT '' AS one, f.* FROM FLOAT8_TBL f WHERE f.f1 = '1004.3';
151 SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE '1004.3' > f.f1;
153 -------+----------------------
156 | 1.2345678901234e-200
159 SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE f.f1 < '1004.3';
161 -------+----------------------
164 | 1.2345678901234e-200
167 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE '1004.3' >= f.f1;
169 ------+----------------------
173 | 1.2345678901234e-200
176 SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <= '1004.3';
178 ------+----------------------
182 | 1.2345678901234e-200
185 SELECT '' AS three, f.f1, f.f1 * '-10' AS x
189 -------+----------------------+-----------------------
191 | 1.2345678901234e+200 | -1.2345678901234e+201
192 | 1.2345678901234e-200 | -1.2345678901234e-199
195 SELECT '' AS three, f.f1, f.f1 + '-10' AS x
199 -------+----------------------+----------------------
201 | 1.2345678901234e+200 | 1.2345678901234e+200
202 | 1.2345678901234e-200 | -10
205 SELECT '' AS three, f.f1, f.f1 / '-10' AS x
209 -------+----------------------+-----------------------
211 | 1.2345678901234e+200 | -1.2345678901234e+199
212 | 1.2345678901234e-200 | -1.2345678901234e-201
215 SELECT '' AS three, f.f1, f.f1 - '-10' AS x
219 -------+----------------------+----------------------
221 | 1.2345678901234e+200 | 1.2345678901234e+200
222 | 1.2345678901234e-200 | 10
225 SELECT '' AS one, f.f1 ^ '2.0' AS square_f1
226 FROM FLOAT8_TBL f where f.f1 = '1004.3';
233 SELECT '' AS five, f.f1, @f.f1 AS abs_f1
236 ------+----------------------+----------------------
240 | 1.2345678901234e+200 | 1.2345678901234e+200
241 | 1.2345678901234e-200 | 1.2345678901234e-200
245 SELECT '' AS five, f.f1, trunc(f.f1) AS trunc_f1
248 ------+----------------------+----------------------
252 | 1.2345678901234e+200 | 1.2345678901234e+200
253 | 1.2345678901234e-200 | 0
257 SELECT '' AS five, f.f1, round(f.f1) AS round_f1
260 ------+----------------------+----------------------
264 | 1.2345678901234e+200 | 1.2345678901234e+200
265 | 1.2345678901234e-200 | 0
269 select ceil(f1) as ceil_f1 from float8_tbl f;
271 ----------------------
279 select ceiling(f1) as ceiling_f1 from float8_tbl f;
281 ----------------------
290 select floor(f1) as floor_f1 from float8_tbl f;
292 ----------------------
301 select sign(f1) as sign_f1 from float8_tbl f;
312 SELECT sqrt(float8 '64') AS eight;
318 SELECT |/ float8 '64' AS eight;
324 SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
328 -------+----------------------+-----------------------
329 | 1004.3 | 31.6906926399535
330 | 1.2345678901234e+200 | 1.11111110611109e+100
331 | 1.2345678901234e-200 | 1.11111110611109e-100
335 SELECT power(float8 '144', float8 '0.5');
341 -- take exp of ln(f.f1)
342 SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
345 three | f1 | exp_ln_f1
346 -------+----------------------+-----------------------
348 | 1.2345678901234e+200 | 1.23456789012338e+200
349 | 1.2345678901234e-200 | 1.23456789012339e-200
353 SELECT ||/ float8 '27' AS three;
359 SELECT '' AS five, f.f1, ||/f.f1 AS cbrt_f1 FROM FLOAT8_TBL f;
361 ------+----------------------+----------------------
363 | 1004.3 | 10.014312837827
364 | -34.84 | -3.26607421344208
365 | 1.2345678901234e+200 | 4.97933859234765e+66
366 | 1.2345678901234e-200 | 2.3112042409018e-67
369 SELECT '' AS five, * FROM FLOAT8_TBL;
371 ------+----------------------
375 | 1.2345678901234e+200
376 | 1.2345678901234e-200
380 SET f1 = FLOAT8_TBL.f1 * '-1'
381 WHERE FLOAT8_TBL.f1 > '0.0';
382 SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
383 ERROR: value out of range: overflow
384 SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
385 ERROR: value out of range: overflow
386 SELECT 0 ^ 0 + 0 ^ 1 + 0 ^ 0.0 + 0 ^ 0.5;
392 SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
393 ERROR: cannot take logarithm of zero
394 SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
395 ERROR: cannot take logarithm of a negative number
396 SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
397 ERROR: value out of range: underflow
398 SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
399 ERROR: division by zero
400 SELECT '' AS five, * FROM FLOAT8_TBL;
402 ------+-----------------------
406 | -1.2345678901234e+200
407 | -1.2345678901234e-200
410 -- test for over- and underflow
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 ('-10e400');
416 ERROR: "-10e400" is out of range for type double precision
417 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
419 INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
420 INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
421 -- maintain external table consistency across platforms
422 -- delete all values and reinsert well-behaved ones
423 DELETE FROM FLOAT8_TBL;
424 INSERT INTO FLOAT8_TBL(f1) VALUES ('0.0');
425 INSERT INTO FLOAT8_TBL(f1) VALUES ('-34.84');
426 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1004.30');
427 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e+200');
428 INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e-200');
429 SELECT '' AS five, * FROM FLOAT8_TBL;
431 ------+-----------------------
435 | -1.2345678901234e+200
436 | -1.2345678901234e-200