Commit c015f853 authored by Tom Lane's avatar Tom Lane

Adjust the tests for the hyperbolic functions.

Preliminary results from the buildfarm suggest that no platform gets
commit c6f153dc's test cases wrong by more than one or two units in
the last place, so setting extra_float_digits = 0 should be plenty
to hide the cross-platform variations.

Also, add tests for Infinity/NaN inputs.  I think it highly likely
that we'll end up removing these again, rather than adding code to
make ancient platforms conform.  But it seems useful to find out
just how many platforms have such issues before we make a decision.

Discussion: https://postgr.es/m/E1h3nUY-0000sM-Vf@gemulon.postgresql.org
parent c6f153dc
......@@ -454,24 +454,25 @@ SELECT '' AS five, * FROM FLOAT8_TBL;
| -1.2345678901234e-200
(5 rows)
RESET extra_float_digits;
-- hyperbolic functions
-- we run these with extra_float_digits = 0 too, since different platforms
-- tend to produce results that vary in the last place.
SELECT sinh(float8 '1');
sinh
--------------------
1.1752011936438014
-----------------
1.1752011936438
(1 row)
SELECT cosh(float8 '1');
cosh
--------------------
1.5430806348152437
------------------
1.54308063481524
(1 row)
SELECT tanh(float8 '1');
tanh
--------------------
0.7615941559557649
-------------------
0.761594155955765
(1 row)
SELECT asinh(float8 '1');
......@@ -482,16 +483,114 @@ SELECT asinh(float8 '1');
SELECT acosh(float8 '2');
acosh
--------------------
1.3169578969248166
------------------
1.31695789692482
(1 row)
SELECT atanh(float8 '0.5');
atanh
--------------------
0.5493061443340548
-------------------
0.549306144334055
(1 row)
-- test Inf/NaN cases for hyperbolic functions
SELECT sinh(float8 'infinity');
sinh
----------
Infinity
(1 row)
SELECT sinh(float8 '-infinity');
sinh
-----------
-Infinity
(1 row)
SELECT sinh(float8 'nan');
sinh
------
NaN
(1 row)
SELECT cosh(float8 'infinity');
cosh
----------
Infinity
(1 row)
SELECT cosh(float8 '-infinity');
cosh
----------
Infinity
(1 row)
SELECT cosh(float8 'nan');
cosh
------
NaN
(1 row)
SELECT tanh(float8 'infinity');
tanh
------
1
(1 row)
SELECT tanh(float8 '-infinity');
tanh
------
-1
(1 row)
SELECT tanh(float8 'nan');
tanh
------
NaN
(1 row)
SELECT asinh(float8 'infinity');
asinh
----------
Infinity
(1 row)
SELECT asinh(float8 '-infinity');
asinh
-----------
-Infinity
(1 row)
SELECT asinh(float8 'nan');
asinh
-------
NaN
(1 row)
SELECT acosh(float8 'infinity');
acosh
----------
Infinity
(1 row)
SELECT acosh(float8 '-infinity');
ERROR: input is out of range
SELECT acosh(float8 'nan');
acosh
-------
NaN
(1 row)
SELECT atanh(float8 'infinity');
ERROR: input is out of range
SELECT atanh(float8 '-infinity');
ERROR: input is out of range
SELECT atanh(float8 'nan');
atanh
-------
NaN
(1 row)
RESET extra_float_digits;
-- test for over- and underflow
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
ERROR: "10e400" is out of range for type double precision
......
......@@ -154,15 +154,36 @@ SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
SELECT '' AS five, * FROM FLOAT8_TBL;
RESET extra_float_digits;
-- hyperbolic functions
-- we run these with extra_float_digits = 0 too, since different platforms
-- tend to produce results that vary in the last place.
SELECT sinh(float8 '1');
SELECT cosh(float8 '1');
SELECT tanh(float8 '1');
SELECT asinh(float8 '1');
SELECT acosh(float8 '2');
SELECT atanh(float8 '0.5');
-- test Inf/NaN cases for hyperbolic functions
SELECT sinh(float8 'infinity');
SELECT sinh(float8 '-infinity');
SELECT sinh(float8 'nan');
SELECT cosh(float8 'infinity');
SELECT cosh(float8 '-infinity');
SELECT cosh(float8 'nan');
SELECT tanh(float8 'infinity');
SELECT tanh(float8 '-infinity');
SELECT tanh(float8 'nan');
SELECT asinh(float8 'infinity');
SELECT asinh(float8 '-infinity');
SELECT asinh(float8 'nan');
SELECT acosh(float8 'infinity');
SELECT acosh(float8 '-infinity');
SELECT acosh(float8 'nan');
SELECT atanh(float8 'infinity');
SELECT atanh(float8 '-infinity');
SELECT atanh(float8 'nan');
RESET extra_float_digits;
-- test for over- and underflow
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment