2000-01-04 17:19:34 +01:00
|
|
|
--
|
|
|
|
-- FLOAT8
|
|
|
|
--
|
|
|
|
CREATE TABLE FLOAT8_TBL(f1 float8);
|
2004-03-11 03:11:14 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES (' 0.0 ');
|
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('1004.30 ');
|
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES (' -34.84');
|
2000-01-04 17:19:34 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('1.2345678901234e+200');
|
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('1.2345678901234e-200');
|
2004-03-24 03:02:27 +01:00
|
|
|
-- test for underflow and overflow handling
|
|
|
|
SELECT '10e400'::float8;
|
2004-03-11 03:11:14 +01:00
|
|
|
ERROR: "10e400" is out of range for type double precision
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: SELECT '10e400'::float8;
|
|
|
|
^
|
2004-03-24 03:02:27 +01:00
|
|
|
SELECT '-10e400'::float8;
|
2004-03-11 03:11:14 +01:00
|
|
|
ERROR: "-10e400" is out of range for type double precision
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: SELECT '-10e400'::float8;
|
|
|
|
^
|
2004-03-24 03:02:27 +01:00
|
|
|
SELECT '10e-400'::float8;
|
2004-03-11 03:11:14 +01:00
|
|
|
ERROR: "10e-400" is out of range for type double precision
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: SELECT '10e-400'::float8;
|
|
|
|
^
|
2004-03-24 03:02:27 +01:00
|
|
|
SELECT '-10e-400'::float8;
|
2004-03-11 03:11:14 +01:00
|
|
|
ERROR: "-10e-400" is out of range for type double precision
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: SELECT '-10e-400'::float8;
|
|
|
|
^
|
2004-03-11 03:11:14 +01:00
|
|
|
-- bad input
|
2005-02-11 05:09:05 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('');
|
|
|
|
ERROR: invalid input syntax for type double precision: ""
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('');
|
|
|
|
^
|
2004-03-11 03:11:14 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
|
|
|
ERROR: invalid input syntax for type double precision: " "
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
|
|
|
|
^
|
2004-03-11 03:11:14 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
|
|
|
ERROR: invalid input syntax for type double precision: "xyz"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
|
|
|
|
^
|
2004-03-11 03:11:14 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
|
|
|
|
ERROR: invalid input syntax for type double precision: "5.0.0"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
|
|
|
|
^
|
2004-03-11 03:11:14 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
|
|
|
|
ERROR: invalid input syntax for type double precision: "5 . 0"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
|
|
|
|
^
|
2004-03-11 03:11:14 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('5. 0');
|
|
|
|
ERROR: invalid input syntax for type double precision: "5. 0"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5. 0');
|
|
|
|
^
|
2004-03-11 03:11:14 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES (' - 3');
|
|
|
|
ERROR: invalid input syntax for type double precision: " - 3"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES (' - 3');
|
|
|
|
^
|
2004-03-11 03:11:14 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('123 5');
|
|
|
|
ERROR: invalid input syntax for type double precision: "123 5"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('123 5');
|
|
|
|
^
|
2004-03-11 03:11:14 +01:00
|
|
|
-- special inputs
|
|
|
|
SELECT 'NaN'::float8;
|
|
|
|
float8
|
|
|
|
--------
|
|
|
|
NaN
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT 'nan'::float8;
|
|
|
|
float8
|
|
|
|
--------
|
|
|
|
NaN
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ' NAN '::float8;
|
|
|
|
float8
|
|
|
|
--------
|
|
|
|
NaN
|
|
|
|
(1 row)
|
|
|
|
|
2004-03-12 01:25:43 +01:00
|
|
|
SELECT 'infinity'::float8;
|
|
|
|
float8
|
|
|
|
----------
|
|
|
|
Infinity
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ' -INFINiTY '::float8;
|
|
|
|
float8
|
|
|
|
-----------
|
|
|
|
-Infinity
|
|
|
|
(1 row)
|
|
|
|
|
2004-03-11 03:11:14 +01:00
|
|
|
-- bad special inputs
|
|
|
|
SELECT 'N A N'::float8;
|
|
|
|
ERROR: invalid input syntax for type double precision: "N A N"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: SELECT 'N A N'::float8;
|
|
|
|
^
|
2004-03-12 01:25:43 +01:00
|
|
|
SELECT 'NaN x'::float8;
|
|
|
|
ERROR: invalid input syntax for type double precision: "NaN x"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: SELECT 'NaN x'::float8;
|
|
|
|
^
|
2004-03-12 01:25:43 +01:00
|
|
|
SELECT ' INFINITY x'::float8;
|
|
|
|
ERROR: invalid input syntax for type double precision: " INFINITY x"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: SELECT ' INFINITY x'::float8;
|
|
|
|
^
|
2004-03-12 01:25:43 +01:00
|
|
|
SELECT 'Infinity'::float8 + 100.0;
|
2007-01-02 21:00:50 +01:00
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
Infinity
|
|
|
|
(1 row)
|
|
|
|
|
2004-03-12 01:25:43 +01:00
|
|
|
SELECT 'Infinity'::float8 / 'Infinity'::float8;
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
NaN
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT 'nan'::float8 / 'nan'::float8;
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
NaN
|
|
|
|
(1 row)
|
|
|
|
|
2010-02-27 22:53:21 +01:00
|
|
|
SELECT 'nan'::numeric::float8;
|
|
|
|
float8
|
|
|
|
--------
|
|
|
|
NaN
|
|
|
|
(1 row)
|
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS five, * FROM FLOAT8_TBL;
|
2000-01-04 17:19:34 +01:00
|
|
|
five | f1
|
|
|
|
------+----------------------
|
|
|
|
| 0
|
|
|
|
| 1004.3
|
|
|
|
| -34.84
|
|
|
|
| 1.2345678901234e+200
|
|
|
|
| 1.2345678901234e-200
|
1997-04-05 13:24:54 +02:00
|
|
|
(5 rows)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <> '1004.3';
|
|
|
|
four | f1
|
|
|
|
------+----------------------
|
|
|
|
| 0
|
|
|
|
| -34.84
|
|
|
|
| 1.2345678901234e+200
|
|
|
|
| 1.2345678901234e-200
|
1997-04-05 13:24:54 +02:00
|
|
|
(4 rows)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS one, f.* FROM FLOAT8_TBL f WHERE f.f1 = '1004.3';
|
|
|
|
one | f1
|
|
|
|
-----+--------
|
|
|
|
| 1004.3
|
1997-04-05 13:24:54 +02:00
|
|
|
(1 row)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE '1004.3' > f.f1;
|
|
|
|
three | f1
|
|
|
|
-------+----------------------
|
|
|
|
| 0
|
|
|
|
| -34.84
|
|
|
|
| 1.2345678901234e-200
|
1997-04-05 13:24:54 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE f.f1 < '1004.3';
|
|
|
|
three | f1
|
|
|
|
-------+----------------------
|
|
|
|
| 0
|
|
|
|
| -34.84
|
|
|
|
| 1.2345678901234e-200
|
1997-04-05 13:24:54 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE '1004.3' >= f.f1;
|
|
|
|
four | f1
|
|
|
|
------+----------------------
|
|
|
|
| 0
|
|
|
|
| 1004.3
|
|
|
|
| -34.84
|
|
|
|
| 1.2345678901234e-200
|
1997-04-05 13:24:54 +02:00
|
|
|
(4 rows)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1 <= '1004.3';
|
|
|
|
four | f1
|
|
|
|
------+----------------------
|
|
|
|
| 0
|
|
|
|
| 1004.3
|
|
|
|
| -34.84
|
|
|
|
| 1.2345678901234e-200
|
1997-04-05 13:24:54 +02:00
|
|
|
(4 rows)
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
SELECT '' AS three, f.f1, f.f1 * '-10' AS x
|
1997-04-05 13:24:54 +02:00
|
|
|
FROM FLOAT8_TBL f
|
|
|
|
WHERE f.f1 > '0.0';
|
2000-01-04 17:19:34 +01:00
|
|
|
three | f1 | x
|
|
|
|
-------+----------------------+-----------------------
|
|
|
|
| 1004.3 | -10043
|
|
|
|
| 1.2345678901234e+200 | -1.2345678901234e+201
|
|
|
|
| 1.2345678901234e-200 | -1.2345678901234e-199
|
1997-04-05 13:24:54 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS three, f.f1, f.f1 + '-10' AS x
|
1997-04-05 13:24:54 +02:00
|
|
|
FROM FLOAT8_TBL f
|
|
|
|
WHERE f.f1 > '0.0';
|
2000-01-04 17:19:34 +01:00
|
|
|
three | f1 | x
|
|
|
|
-------+----------------------+----------------------
|
|
|
|
| 1004.3 | 994.3
|
|
|
|
| 1.2345678901234e+200 | 1.2345678901234e+200
|
|
|
|
| 1.2345678901234e-200 | -10
|
1997-04-05 13:24:54 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS three, f.f1, f.f1 / '-10' AS x
|
1997-04-05 13:24:54 +02:00
|
|
|
FROM FLOAT8_TBL f
|
|
|
|
WHERE f.f1 > '0.0';
|
2000-01-04 17:19:34 +01:00
|
|
|
three | f1 | x
|
|
|
|
-------+----------------------+-----------------------
|
|
|
|
| 1004.3 | -100.43
|
|
|
|
| 1.2345678901234e+200 | -1.2345678901234e+199
|
|
|
|
| 1.2345678901234e-200 | -1.2345678901234e-201
|
1997-04-05 13:24:54 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS three, f.f1, f.f1 - '-10' AS x
|
1997-04-05 13:24:54 +02:00
|
|
|
FROM FLOAT8_TBL f
|
|
|
|
WHERE f.f1 > '0.0';
|
2000-01-04 17:19:34 +01:00
|
|
|
three | f1 | x
|
|
|
|
-------+----------------------+----------------------
|
|
|
|
| 1004.3 | 1014.3
|
|
|
|
| 1.2345678901234e+200 | 1.2345678901234e+200
|
|
|
|
| 1.2345678901234e-200 | 10
|
1997-04-05 13:24:54 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS one, f.f1 ^ '2.0' AS square_f1
|
1997-04-05 13:24:54 +02:00
|
|
|
FROM FLOAT8_TBL f where f.f1 = '1004.3';
|
2000-01-04 17:19:34 +01:00
|
|
|
one | square_f1
|
|
|
|
-----+------------
|
|
|
|
| 1008618.49
|
1997-04-05 13:24:54 +02:00
|
|
|
(1 row)
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- absolute value
|
|
|
|
SELECT '' AS five, f.f1, @f.f1 AS abs_f1
|
1997-04-05 13:24:54 +02:00
|
|
|
FROM FLOAT8_TBL f;
|
2000-01-04 17:19:34 +01:00
|
|
|
five | f1 | abs_f1
|
|
|
|
------+----------------------+----------------------
|
|
|
|
| 0 | 0
|
|
|
|
| 1004.3 | 1004.3
|
|
|
|
| -34.84 | 34.84
|
|
|
|
| 1.2345678901234e+200 | 1.2345678901234e+200
|
|
|
|
| 1.2345678901234e-200 | 1.2345678901234e-200
|
1997-04-05 13:24:54 +02:00
|
|
|
(5 rows)
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- truncate
|
2005-06-08 23:15:29 +02:00
|
|
|
SELECT '' AS five, f.f1, trunc(f.f1) AS trunc_f1
|
1997-04-05 13:24:54 +02:00
|
|
|
FROM FLOAT8_TBL f;
|
2000-01-04 17:19:34 +01:00
|
|
|
five | f1 | trunc_f1
|
|
|
|
------+----------------------+----------------------
|
|
|
|
| 0 | 0
|
|
|
|
| 1004.3 | 1004
|
|
|
|
| -34.84 | -34
|
|
|
|
| 1.2345678901234e+200 | 1.2345678901234e+200
|
|
|
|
| 1.2345678901234e-200 | 0
|
1997-04-05 13:24:54 +02:00
|
|
|
(5 rows)
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- round
|
2005-06-08 23:15:29 +02:00
|
|
|
SELECT '' AS five, f.f1, round(f.f1) AS round_f1
|
1997-04-05 13:24:54 +02:00
|
|
|
FROM FLOAT8_TBL f;
|
2000-01-04 17:19:34 +01:00
|
|
|
five | f1 | round_f1
|
|
|
|
------+----------------------+----------------------
|
|
|
|
| 0 | 0
|
|
|
|
| 1004.3 | 1004
|
|
|
|
| -34.84 | -35
|
|
|
|
| 1.2345678901234e+200 | 1.2345678901234e+200
|
|
|
|
| 1.2345678901234e-200 | 0
|
1997-04-05 13:24:54 +02:00
|
|
|
(5 rows)
|
|
|
|
|
2004-04-23 22:32:20 +02:00
|
|
|
-- ceil / ceiling
|
2002-10-19 04:08:19 +02:00
|
|
|
select ceil(f1) as ceil_f1 from float8_tbl f;
|
|
|
|
ceil_f1
|
|
|
|
----------------------
|
|
|
|
0
|
|
|
|
1005
|
|
|
|
-34
|
|
|
|
1.2345678901234e+200
|
|
|
|
1
|
|
|
|
(5 rows)
|
|
|
|
|
2004-04-23 22:32:20 +02:00
|
|
|
select ceiling(f1) as ceiling_f1 from float8_tbl f;
|
|
|
|
ceiling_f1
|
|
|
|
----------------------
|
|
|
|
0
|
|
|
|
1005
|
|
|
|
-34
|
|
|
|
1.2345678901234e+200
|
|
|
|
1
|
|
|
|
(5 rows)
|
|
|
|
|
2002-10-19 04:08:19 +02:00
|
|
|
-- floor
|
|
|
|
select floor(f1) as floor_f1 from float8_tbl f;
|
|
|
|
floor_f1
|
|
|
|
----------------------
|
|
|
|
0
|
|
|
|
1004
|
|
|
|
-35
|
|
|
|
1.2345678901234e+200
|
|
|
|
0
|
|
|
|
(5 rows)
|
|
|
|
|
|
|
|
-- sign
|
|
|
|
select sign(f1) as sign_f1 from float8_tbl f;
|
|
|
|
sign_f1
|
|
|
|
---------
|
|
|
|
0
|
|
|
|
1
|
|
|
|
-1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
(5 rows)
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- square root
|
2000-03-15 00:06:59 +01:00
|
|
|
SELECT sqrt(float8 '64') AS eight;
|
|
|
|
eight
|
|
|
|
-------
|
|
|
|
8
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT |/ float8 '64' AS eight;
|
|
|
|
eight
|
|
|
|
-------
|
|
|
|
8
|
|
|
|
(1 row)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1
|
1997-04-05 13:24:54 +02:00
|
|
|
FROM FLOAT8_TBL f
|
|
|
|
WHERE f.f1 > '0.0';
|
2000-01-04 17:19:34 +01:00
|
|
|
three | f1 | sqrt_f1
|
|
|
|
-------+----------------------+-----------------------
|
|
|
|
| 1004.3 | 31.6906926399535
|
|
|
|
| 1.2345678901234e+200 | 1.11111110611109e+100
|
|
|
|
| 1.2345678901234e-200 | 1.11111110611109e-100
|
1997-04-05 13:24:54 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2004-04-23 22:32:20 +02:00
|
|
|
-- power
|
|
|
|
SELECT power(float8 '144', float8 '0.5');
|
|
|
|
power
|
|
|
|
-------
|
|
|
|
12
|
|
|
|
(1 row)
|
|
|
|
|
2018-04-29 21:21:44 +02:00
|
|
|
SELECT power(float8 'NaN', float8 '0.5');
|
|
|
|
power
|
|
|
|
-------
|
|
|
|
NaN
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT power(float8 '144', float8 'NaN');
|
|
|
|
power
|
|
|
|
-------
|
|
|
|
NaN
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT power(float8 'NaN', float8 'NaN');
|
|
|
|
power
|
|
|
|
-------
|
|
|
|
NaN
|
|
|
|
(1 row)
|
|
|
|
|
2018-04-30 00:15:16 +02:00
|
|
|
SELECT power(float8 '-1', float8 'NaN');
|
|
|
|
power
|
|
|
|
-------
|
|
|
|
NaN
|
|
|
|
(1 row)
|
|
|
|
|
2018-04-29 21:21:44 +02:00
|
|
|
SELECT power(float8 '1', float8 'NaN');
|
|
|
|
power
|
|
|
|
-------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT power(float8 'NaN', float8 '0');
|
|
|
|
power
|
|
|
|
-------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- take exp of ln(f.f1)
|
2000-03-20 06:19:11 +01:00
|
|
|
SELECT '' AS three, f.f1, exp(ln(f.f1)) AS exp_ln_f1
|
1997-04-05 13:24:54 +02:00
|
|
|
FROM FLOAT8_TBL f
|
|
|
|
WHERE f.f1 > '0.0';
|
2000-01-04 17:19:34 +01:00
|
|
|
three | f1 | exp_ln_f1
|
|
|
|
-------+----------------------+-----------------------
|
|
|
|
| 1004.3 | 1004.3
|
|
|
|
| 1.2345678901234e+200 | 1.23456789012338e+200
|
|
|
|
| 1.2345678901234e-200 | 1.23456789012339e-200
|
1997-04-05 13:24:54 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- cube root
|
2000-03-15 00:06:59 +01:00
|
|
|
SELECT ||/ float8 '27' AS three;
|
|
|
|
three
|
|
|
|
-------
|
|
|
|
3
|
|
|
|
(1 row)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS five, f.f1, ||/f.f1 AS cbrt_f1 FROM FLOAT8_TBL f;
|
|
|
|
five | f1 | cbrt_f1
|
|
|
|
------+----------------------+----------------------
|
|
|
|
| 0 | 0
|
|
|
|
| 1004.3 | 10.014312837827
|
|
|
|
| -34.84 | -3.26607421344208
|
|
|
|
| 1.2345678901234e+200 | 4.97933859234765e+66
|
|
|
|
| 1.2345678901234e-200 | 2.3112042409018e-67
|
1997-04-05 13:24:54 +02:00
|
|
|
(5 rows)
|
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS five, * FROM FLOAT8_TBL;
|
2000-01-04 17:19:34 +01:00
|
|
|
five | f1
|
|
|
|
------+----------------------
|
|
|
|
| 0
|
|
|
|
| 1004.3
|
|
|
|
| -34.84
|
|
|
|
| 1.2345678901234e+200
|
|
|
|
| 1.2345678901234e-200
|
1997-04-05 13:24:54 +02:00
|
|
|
(5 rows)
|
|
|
|
|
2000-01-04 17:19:34 +01:00
|
|
|
UPDATE FLOAT8_TBL
|
1997-04-05 13:24:54 +02:00
|
|
|
SET f1 = FLOAT8_TBL.f1 * '-1'
|
|
|
|
WHERE FLOAT8_TBL.f1 > '0.0';
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
|
2007-01-02 21:00:50 +01:00
|
|
|
ERROR: value out of range: overflow
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
|
2007-01-02 21:00:50 +01:00
|
|
|
ERROR: value out of range: overflow
|
2008-05-09 00:17:54 +02:00
|
|
|
SELECT 0 ^ 0 + 0 ^ 1 + 0 ^ 0.0 + 0 ^ 0.5;
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
2000-03-20 06:19:11 +01:00
|
|
|
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot take logarithm of zero
|
2000-03-20 06:19:11 +01:00
|
|
|
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot take logarithm of a negative number
|
2000-03-20 06:19:11 +01:00
|
|
|
SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
|
2007-01-02 21:00:50 +01:00
|
|
|
ERROR: value out of range: underflow
|
2000-01-04 17:19:34 +01:00
|
|
|
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
|
2003-03-11 22:01:33 +01:00
|
|
|
ERROR: division by zero
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS five, * FROM FLOAT8_TBL;
|
2000-01-04 17:19:34 +01:00
|
|
|
five | f1
|
|
|
|
------+-----------------------
|
|
|
|
| 0
|
|
|
|
| -34.84
|
|
|
|
| -1004.3
|
|
|
|
| -1.2345678901234e+200
|
|
|
|
| -1.2345678901234e-200
|
1997-04-05 13:24:54 +02:00
|
|
|
(5 rows)
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- test for over- and underflow
|
2000-01-04 17:19:34 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: "10e400" is out of range for type double precision
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
|
|
|
|
^
|
2000-01-04 17:19:34 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: "-10e400" is out of range for type double precision
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
|
|
|
|
^
|
2000-01-04 17:19:34 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: "10e-400" is out of range for type double precision
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
|
|
|
|
^
|
2000-01-04 17:19:34 +01:00
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: "-10e-400" is out of range for type double precision
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
|
|
|
|
^
|
2000-01-04 17:19:34 +01:00
|
|
|
-- maintain external table consistency across platforms
|
|
|
|
-- delete all values and reinsert well-behaved ones
|
|
|
|
DELETE FROM FLOAT8_TBL;
|
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('0.0');
|
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('-34.84');
|
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('-1004.30');
|
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e+200');
|
|
|
|
INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e-200');
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS five, * FROM FLOAT8_TBL;
|
2000-01-04 17:19:34 +01:00
|
|
|
five | f1
|
|
|
|
------+-----------------------
|
|
|
|
| 0
|
|
|
|
| -34.84
|
|
|
|
| -1004.3
|
|
|
|
| -1.2345678901234e+200
|
|
|
|
| -1.2345678901234e-200
|
1998-09-22 18:52:59 +02:00
|
|
|
(5 rows)
|
|
|
|
|
2018-11-24 02:57:11 +01:00
|
|
|
-- test edge-case coercions to integer
|
|
|
|
SELECT '32767.4'::float8::int2;
|
|
|
|
int2
|
|
|
|
-------
|
|
|
|
32767
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '32767.6'::float8::int2;
|
|
|
|
ERROR: smallint out of range
|
|
|
|
SELECT '-32768.4'::float8::int2;
|
|
|
|
int2
|
|
|
|
--------
|
|
|
|
-32768
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '-32768.6'::float8::int2;
|
|
|
|
ERROR: smallint out of range
|
|
|
|
SELECT '2147483647.4'::float8::int4;
|
|
|
|
int4
|
|
|
|
------------
|
|
|
|
2147483647
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '2147483647.6'::float8::int4;
|
|
|
|
ERROR: integer out of range
|
|
|
|
SELECT '-2147483648.4'::float8::int4;
|
|
|
|
int4
|
|
|
|
-------------
|
|
|
|
-2147483648
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '-2147483648.6'::float8::int4;
|
|
|
|
ERROR: integer out of range
|
2018-11-24 05:49:25 +01:00
|
|
|
SELECT '9223372036854773760'::float8::int8;
|
2018-11-24 02:57:11 +01:00
|
|
|
int8
|
|
|
|
---------------------
|
2018-11-24 05:49:25 +01:00
|
|
|
9223372036854773760
|
2018-11-24 02:57:11 +01:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '9223372036854775807'::float8::int8;
|
|
|
|
ERROR: bigint out of range
|
|
|
|
SELECT '-9223372036854775808.5'::float8::int8;
|
|
|
|
int8
|
|
|
|
----------------------
|
|
|
|
-9223372036854775808
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '-9223372036854780000'::float8::int8;
|
|
|
|
ERROR: bigint out of range
|
2016-01-22 21:46:22 +01:00
|
|
|
-- test exact cases for trigonometric functions in degrees
|
2016-04-19 22:47:21 +02:00
|
|
|
SET extra_float_digits = 3;
|
2016-01-22 21:46:22 +01:00
|
|
|
SELECT x,
|
2016-04-19 22:47:21 +02:00
|
|
|
sind(x),
|
|
|
|
sind(x) IN (-1,-0.5,0,0.5,1) AS sind_exact
|
|
|
|
FROM (VALUES (0), (30), (90), (150), (180),
|
|
|
|
(210), (270), (330), (360)) AS t(x);
|
|
|
|
x | sind | sind_exact
|
|
|
|
-----+------+------------
|
|
|
|
0 | 0 | t
|
|
|
|
30 | 0.5 | t
|
|
|
|
90 | 1 | t
|
|
|
|
150 | 0.5 | t
|
|
|
|
180 | 0 | t
|
|
|
|
210 | -0.5 | t
|
|
|
|
270 | -1 | t
|
|
|
|
330 | -0.5 | t
|
|
|
|
360 | 0 | t
|
|
|
|
(9 rows)
|
2016-01-22 21:46:22 +01:00
|
|
|
|
|
|
|
SELECT x,
|
2016-04-19 22:47:21 +02:00
|
|
|
cosd(x),
|
|
|
|
cosd(x) IN (-1,-0.5,0,0.5,1) AS cosd_exact
|
|
|
|
FROM (VALUES (0), (60), (90), (120), (180),
|
|
|
|
(240), (270), (300), (360)) AS t(x);
|
|
|
|
x | cosd | cosd_exact
|
|
|
|
-----+------+------------
|
|
|
|
0 | 1 | t
|
|
|
|
60 | 0.5 | t
|
|
|
|
90 | 0 | t
|
|
|
|
120 | -0.5 | t
|
|
|
|
180 | -1 | t
|
|
|
|
240 | -0.5 | t
|
|
|
|
270 | 0 | t
|
|
|
|
300 | 0.5 | t
|
|
|
|
360 | 1 | t
|
|
|
|
(9 rows)
|
|
|
|
|
|
|
|
SELECT x,
|
|
|
|
tand(x),
|
|
|
|
tand(x) IN ('-Infinity'::float8,-1,0,
|
|
|
|
1,'Infinity'::float8) AS tand_exact,
|
|
|
|
cotd(x),
|
|
|
|
cotd(x) IN ('-Infinity'::float8,-1,0,
|
|
|
|
1,'Infinity'::float8) AS cotd_exact
|
|
|
|
FROM (VALUES (0), (45), (90), (135), (180),
|
|
|
|
(225), (270), (315), (360)) AS t(x);
|
|
|
|
x | tand | tand_exact | cotd | cotd_exact
|
|
|
|
-----+-----------+------------+-----------+------------
|
|
|
|
0 | 0 | t | Infinity | t
|
|
|
|
45 | 1 | t | 1 | t
|
|
|
|
90 | Infinity | t | 0 | t
|
|
|
|
135 | -1 | t | -1 | t
|
|
|
|
180 | 0 | t | -Infinity | t
|
|
|
|
225 | 1 | t | 1 | t
|
|
|
|
270 | -Infinity | t | 0 | t
|
|
|
|
315 | -1 | t | -1 | t
|
|
|
|
360 | 0 | t | Infinity | t
|
|
|
|
(9 rows)
|
|
|
|
|
|
|
|
SELECT x,
|
|
|
|
asind(x),
|
|
|
|
asind(x) IN (-90,-30,0,30,90) AS asind_exact,
|
|
|
|
acosd(x),
|
|
|
|
acosd(x) IN (0,60,90,120,180) AS acosd_exact
|
2016-01-22 21:46:22 +01:00
|
|
|
FROM (VALUES (-1), (-0.5), (0), (0.5), (1)) AS t(x);
|
2016-04-19 22:47:21 +02:00
|
|
|
x | asind | asind_exact | acosd | acosd_exact
|
|
|
|
------+-------+-------------+-------+-------------
|
|
|
|
-1 | -90 | t | 180 | t
|
|
|
|
-0.5 | -30 | t | 120 | t
|
|
|
|
0 | 0 | t | 90 | t
|
|
|
|
0.5 | 30 | t | 60 | t
|
|
|
|
1 | 90 | t | 0 | t
|
2016-01-22 21:46:22 +01:00
|
|
|
(5 rows)
|
|
|
|
|
2016-04-19 22:47:21 +02:00
|
|
|
SELECT x,
|
|
|
|
atand(x),
|
|
|
|
atand(x) IN (-90,-45,0,45,90) AS atand_exact
|
|
|
|
FROM (VALUES ('-Infinity'::float8), (-1), (0), (1),
|
|
|
|
('Infinity'::float8)) AS t(x);
|
|
|
|
x | atand | atand_exact
|
|
|
|
-----------+-------+-------------
|
|
|
|
-Infinity | -90 | t
|
|
|
|
-1 | -45 | t
|
|
|
|
0 | 0 | t
|
|
|
|
1 | 45 | t
|
|
|
|
Infinity | 90 | t
|
|
|
|
(5 rows)
|
2016-01-22 21:46:22 +01:00
|
|
|
|
|
|
|
SELECT x, y,
|
2016-04-19 22:47:21 +02:00
|
|
|
atan2d(y, x),
|
|
|
|
atan2d(y, x) IN (-90,0,90,180) AS atan2d_exact
|
2016-01-22 21:46:22 +01:00
|
|
|
FROM (SELECT 10*cosd(a), 10*sind(a)
|
|
|
|
FROM generate_series(0, 360, 90) AS t(a)) AS t(x,y);
|
2016-04-19 22:47:21 +02:00
|
|
|
x | y | atan2d | atan2d_exact
|
|
|
|
-----+-----+--------+--------------
|
|
|
|
10 | 0 | 0 | t
|
|
|
|
0 | 10 | 90 | t
|
|
|
|
-10 | 0 | 180 | t
|
|
|
|
0 | -10 | -90 | t
|
|
|
|
10 | 0 | 0 | t
|
2016-01-22 21:46:22 +01:00
|
|
|
(5 rows)
|
|
|
|
|
2016-04-19 22:47:21 +02:00
|
|
|
RESET extra_float_digits;
|