Adjust the tests for the hyperbolic functions.
authorTom Lane <[email protected]>
Thu, 14 Mar 2019 01:05:33 +0000 (21:05 -0400)
committerTom Lane <[email protected]>
Thu, 14 Mar 2019 01:05:33 +0000 (21:05 -0400)
Preliminary results from the buildfarm suggest that no platform gets
commit c6f153dcf'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/[email protected]

src/test/regress/expected/float8.out
src/test/regress/sql/float8.sql

index 7aed4aa97f80f0fc3ecbd1da12781abca2f95c3d..e85f92ce1986568144aa7b07a036c321dff666eb 100644 (file)
@@ -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
+      sinh       
+-----------------
+ 1.1752011936438
 (1 row)
 
 SELECT cosh(float8 '1');
-        cosh        
---------------------
- 1.5430806348152437
+       cosh       
+------------------
+ 1.54308063481524
 (1 row)
 
 SELECT tanh(float8 '1');
-        tanh        
---------------------
- 0.7615941559557649
+       tanh        
+-------------------
+ 0.761594155955765
 (1 row)
 
 SELECT asinh(float8 '1');
@@ -481,17 +482,115 @@ SELECT asinh(float8 '1');
 (1 row)
 
 SELECT acosh(float8 '2');
-       acosh        
---------------------
- 1.3169578969248166
+      acosh       
+------------------
+ 1.31695789692482
 (1 row)
 
 SELECT atanh(float8 '0.5');
-       atanh        
---------------------
- 0.5493061443340548
+       atanh       
+-------------------
+ 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
index 07fbb66c94700d4d67de17bff6fe397b4cd2ebe5..8385f3bb7b330213cc61b9e8623493548a6785d8 100644 (file)
@@ -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');