Improve regression tests for degree-based trigonometric functions.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 19 Apr 2016 20:47:21 +0000 (16:47 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 19 Apr 2016 20:47:21 +0000 (16:47 -0400)
Print the actual value of each function result that's expected to be exact,
rather than merely emitting a NULL if it's not right.  Although we print
these with extra_float_digits = 3, we should not trust that the platform
will produce a result visibly different from the expected value if it's off
only in the last place; hence, also include comparisons against the exact
values as before.  This is a bit bulkier and uglier than the previous
printout, but it will provide more information and be easier to interpret
if there's a test failure.

Discussion: <18241.1461073100@sss.pgh.pa.us>

src/test/regress/expected/float8-exp-three-digits-win32.out
src/test/regress/expected/float8-small-is-zero.out
src/test/regress/expected/float8-small-is-zero_1.out
src/test/regress/expected/float8.out
src/test/regress/sql/float8.sql

index ae6975679e7b59e48fed4a43accacbfac372788c..7e1153308f55f4f374f1e80636ee16c195649b2b 100644 (file)
@@ -445,79 +445,106 @@ SELECT '' AS five, * FROM FLOAT8_TBL;
 (5 rows)
 
 -- test exact cases for trigonometric functions in degrees
+SET extra_float_digits = 3;
 SELECT x,
-       CASE WHEN sind(x) IN (-1,-0.5,0,0.5,1) THEN sind(x) END AS sind,
-       CASE WHEN cosd(x) IN (-1,-0.5,0,0.5,1) THEN cosd(x) END AS cosd,
-       CASE WHEN tand(x) IN ('-Infinity'::float8,-1,0,
-                             1,'Infinity'::float8) THEN tand(x) END AS tand,
-       CASE WHEN cotd(x) IN ('-Infinity'::float8,-1,0,
-                             1,'Infinity'::float8) THEN cotd(x) END AS cotd
-FROM generate_series(0, 360, 15) AS t(x);
-  x  | sind | cosd |   tand    |   cotd    
------+------+------+-----------+-----------
-   0 |    0 |    1 |         0 |  Infinity
-  15 |      |      |           |          
-  30 |  0.5 |      |           |          
-  45 |      |      |         1 |         1
-  60 |      |  0.5 |           |          
-  75 |      |      |           |          
-  90 |    1 |    0 |  Infinity |         0
- 105 |      |      |           |          
- 120 |      | -0.5 |           |          
- 135 |      |      |        -1 |        -1
- 150 |  0.5 |      |           |          
- 165 |      |      |           |          
- 180 |    0 |   -1 |         0 | -Infinity
- 195 |      |      |           |          
- 210 | -0.5 |      |           |          
- 225 |      |      |         1 |         1
- 240 |      | -0.5 |           |          
- 255 |      |      |           |          
- 270 |   -1 |    0 | -Infinity |         0
- 285 |      |      |           |          
- 300 |      |  0.5 |           |          
- 315 |      |      |        -1 |        -1
- 330 | -0.5 |      |           |          
- 345 |      |      |           |          
- 360 |    0 |    1 |         0 |  Infinity
-(25 rows)
+       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)
 
 SELECT x,
-       CASE WHEN asind(x) IN (-90,-30,0,30,90) THEN asind(x) END AS asind,
-       CASE WHEN acosd(x) IN (0,60,90,120,180) THEN acosd(x) END AS acosd,
-       CASE WHEN atand(x) IN (-45,0,45) THEN atand(x) END AS atand
+       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
 FROM (VALUES (-1), (-0.5), (0), (0.5), (1)) AS t(x);
-  x   | asind | acosd | atand 
-------+-------+-------+-------
-   -1 |   -90 |   180 |   -45
- -0.5 |   -30 |   120 |      
-    0 |     0 |    90 |     0
-  0.5 |    30 |    60 |      
-    1 |    90 |     0 |    45
+  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
 (5 rows)
 
-SELECT atand('-Infinity'::float8) = -90;
- ?column? 
-----------
- t
-(1 row)
-
-SELECT atand('Infinity'::float8) = 90;
- ?column? 
-----------
- t
-(1 row)
+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)
 
 SELECT x, y,
-       CASE WHEN atan2d(y, x) IN (-90,0,90,180) THEN atan2d(y, x) END AS atan2d
+       atan2d(y, x),
+       atan2d(y, x) IN (-90,0,90,180) AS atan2d_exact
 FROM (SELECT 10*cosd(a), 10*sind(a)
       FROM generate_series(0, 360, 90) AS t(a)) AS t(x,y);
-  x  |  y  | atan2d 
------+-----+--------
-  10 |   0 |      0
-   0 |  10 |     90
- -10 |   0 |    180
-   0 | -10 |    -90
-  10 |   0 |      0
+  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
 (5 rows)
 
+RESET extra_float_digits;
index a0294f74136cc05e77452d39b56f79acbd6eb37b..26b83781500c5b884096981a7bf74bdae30a6499 100644 (file)
@@ -443,79 +443,106 @@ SELECT '' AS five, * FROM FLOAT8_TBL;
 (5 rows)
 
 -- test exact cases for trigonometric functions in degrees
+SET extra_float_digits = 3;
 SELECT x,
-       CASE WHEN sind(x) IN (-1,-0.5,0,0.5,1) THEN sind(x) END AS sind,
-       CASE WHEN cosd(x) IN (-1,-0.5,0,0.5,1) THEN cosd(x) END AS cosd,
-       CASE WHEN tand(x) IN ('-Infinity'::float8,-1,0,
-                             1,'Infinity'::float8) THEN tand(x) END AS tand,
-       CASE WHEN cotd(x) IN ('-Infinity'::float8,-1,0,
-                             1,'Infinity'::float8) THEN cotd(x) END AS cotd
-FROM generate_series(0, 360, 15) AS t(x);
-  x  | sind | cosd |   tand    |   cotd    
------+------+------+-----------+-----------
-   0 |    0 |    1 |         0 |  Infinity
-  15 |      |      |           |          
-  30 |  0.5 |      |           |          
-  45 |      |      |         1 |         1
-  60 |      |  0.5 |           |          
-  75 |      |      |           |          
-  90 |    1 |    0 |  Infinity |         0
- 105 |      |      |           |          
- 120 |      | -0.5 |           |          
- 135 |      |      |        -1 |        -1
- 150 |  0.5 |      |           |          
- 165 |      |      |           |          
- 180 |    0 |   -1 |         0 | -Infinity
- 195 |      |      |           |          
- 210 | -0.5 |      |           |          
- 225 |      |      |         1 |         1
- 240 |      | -0.5 |           |          
- 255 |      |      |           |          
- 270 |   -1 |    0 | -Infinity |         0
- 285 |      |      |           |          
- 300 |      |  0.5 |           |          
- 315 |      |      |        -1 |        -1
- 330 | -0.5 |      |           |          
- 345 |      |      |           |          
- 360 |    0 |    1 |         0 |  Infinity
-(25 rows)
+       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)
 
 SELECT x,
-       CASE WHEN asind(x) IN (-90,-30,0,30,90) THEN asind(x) END AS asind,
-       CASE WHEN acosd(x) IN (0,60,90,120,180) THEN acosd(x) END AS acosd,
-       CASE WHEN atand(x) IN (-45,0,45) THEN atand(x) END AS atand
+       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
 FROM (VALUES (-1), (-0.5), (0), (0.5), (1)) AS t(x);
-  x   | asind | acosd | atand 
-------+-------+-------+-------
-   -1 |   -90 |   180 |   -45
- -0.5 |   -30 |   120 |      
-    0 |     0 |    90 |     0
-  0.5 |    30 |    60 |      
-    1 |    90 |     0 |    45
+  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
 (5 rows)
 
-SELECT atand('-Infinity'::float8) = -90;
- ?column? 
-----------
- t
-(1 row)
-
-SELECT atand('Infinity'::float8) = 90;
- ?column? 
-----------
- t
-(1 row)
+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)
 
 SELECT x, y,
-       CASE WHEN atan2d(y, x) IN (-90,0,90,180) THEN atan2d(y, x) END AS atan2d
+       atan2d(y, x),
+       atan2d(y, x) IN (-90,0,90,180) AS atan2d_exact
 FROM (SELECT 10*cosd(a), 10*sind(a)
       FROM generate_series(0, 360, 90) AS t(a)) AS t(x,y);
-  x  |  y  | atan2d 
------+-----+--------
-  10 |   0 |      0
-   0 |  10 |     90
- -10 |   0 |    180
-   0 | -10 |    -90
-  10 |   0 |      0
+  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
 (5 rows)
 
+RESET extra_float_digits;
index d72ab43469cdc3c3ca4f5860168fa791cfe52024..cea27908ebf1df102fa54d16d0212abc7c4a4d3f 100644 (file)
@@ -443,79 +443,106 @@ SELECT '' AS five, * FROM FLOAT8_TBL;
 (5 rows)
 
 -- test exact cases for trigonometric functions in degrees
+SET extra_float_digits = 3;
 SELECT x,
-       CASE WHEN sind(x) IN (-1,-0.5,0,0.5,1) THEN sind(x) END AS sind,
-       CASE WHEN cosd(x) IN (-1,-0.5,0,0.5,1) THEN cosd(x) END AS cosd,
-       CASE WHEN tand(x) IN ('-Infinity'::float8,-1,0,
-                             1,'Infinity'::float8) THEN tand(x) END AS tand,
-       CASE WHEN cotd(x) IN ('-Infinity'::float8,-1,0,
-                             1,'Infinity'::float8) THEN cotd(x) END AS cotd
-FROM generate_series(0, 360, 15) AS t(x);
-  x  | sind | cosd |   tand    |   cotd    
------+------+------+-----------+-----------
-   0 |    0 |    1 |         0 |  Infinity
-  15 |      |      |           |          
-  30 |  0.5 |      |           |          
-  45 |      |      |         1 |         1
-  60 |      |  0.5 |           |          
-  75 |      |      |           |          
-  90 |    1 |    0 |  Infinity |         0
- 105 |      |      |           |          
- 120 |      | -0.5 |           |          
- 135 |      |      |        -1 |        -1
- 150 |  0.5 |      |           |          
- 165 |      |      |           |          
- 180 |    0 |   -1 |         0 | -Infinity
- 195 |      |      |           |          
- 210 | -0.5 |      |           |          
- 225 |      |      |         1 |         1
- 240 |      | -0.5 |           |          
- 255 |      |      |           |          
- 270 |   -1 |    0 | -Infinity |         0
- 285 |      |      |           |          
- 300 |      |  0.5 |           |          
- 315 |      |      |        -1 |        -1
- 330 | -0.5 |      |           |          
- 345 |      |      |           |          
- 360 |    0 |    1 |         0 |  Infinity
-(25 rows)
+       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)
 
 SELECT x,
-       CASE WHEN asind(x) IN (-90,-30,0,30,90) THEN asind(x) END AS asind,
-       CASE WHEN acosd(x) IN (0,60,90,120,180) THEN acosd(x) END AS acosd,
-       CASE WHEN atand(x) IN (-45,0,45) THEN atand(x) END AS atand
+       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
 FROM (VALUES (-1), (-0.5), (0), (0.5), (1)) AS t(x);
-  x   | asind | acosd | atand 
-------+-------+-------+-------
-   -1 |   -90 |   180 |   -45
- -0.5 |   -30 |   120 |      
-    0 |     0 |    90 |     0
-  0.5 |    30 |    60 |      
-    1 |    90 |     0 |    45
+  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
 (5 rows)
 
-SELECT atand('-Infinity'::float8) = -90;
- ?column? 
-----------
- t
-(1 row)
-
-SELECT atand('Infinity'::float8) = 90;
- ?column? 
-----------
- t
-(1 row)
+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)
 
 SELECT x, y,
-       CASE WHEN atan2d(y, x) IN (-90,0,90,180) THEN atan2d(y, x) END AS atan2d
+       atan2d(y, x),
+       atan2d(y, x) IN (-90,0,90,180) AS atan2d_exact
 FROM (SELECT 10*cosd(a), 10*sind(a)
       FROM generate_series(0, 360, 90) AS t(a)) AS t(x,y);
-  x  |  y  | atan2d 
------+-----+--------
-  10 |   0 |      0
-   0 |  10 |     90
- -10 |   0 |    180
-   0 | -10 |    -90
-  10 |   0 |      0
+  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
 (5 rows)
 
+RESET extra_float_digits;
index 8e3dc8f2dbb2ba46bcc2b3fd710a125e5460997d..20c985e5df86ee6bcf603f45bec4df2947e1fad0 100644 (file)
@@ -445,79 +445,106 @@ SELECT '' AS five, * FROM FLOAT8_TBL;
 (5 rows)
 
 -- test exact cases for trigonometric functions in degrees
+SET extra_float_digits = 3;
 SELECT x,
-       CASE WHEN sind(x) IN (-1,-0.5,0,0.5,1) THEN sind(x) END AS sind,
-       CASE WHEN cosd(x) IN (-1,-0.5,0,0.5,1) THEN cosd(x) END AS cosd,
-       CASE WHEN tand(x) IN ('-Infinity'::float8,-1,0,
-                             1,'Infinity'::float8) THEN tand(x) END AS tand,
-       CASE WHEN cotd(x) IN ('-Infinity'::float8,-1,0,
-                             1,'Infinity'::float8) THEN cotd(x) END AS cotd
-FROM generate_series(0, 360, 15) AS t(x);
-  x  | sind | cosd |   tand    |   cotd    
------+------+------+-----------+-----------
-   0 |    0 |    1 |         0 |  Infinity
-  15 |      |      |           |          
-  30 |  0.5 |      |           |          
-  45 |      |      |         1 |         1
-  60 |      |  0.5 |           |          
-  75 |      |      |           |          
-  90 |    1 |    0 |  Infinity |         0
- 105 |      |      |           |          
- 120 |      | -0.5 |           |          
- 135 |      |      |        -1 |        -1
- 150 |  0.5 |      |           |          
- 165 |      |      |           |          
- 180 |    0 |   -1 |         0 | -Infinity
- 195 |      |      |           |          
- 210 | -0.5 |      |           |          
- 225 |      |      |         1 |         1
- 240 |      | -0.5 |           |          
- 255 |      |      |           |          
- 270 |   -1 |    0 | -Infinity |         0
- 285 |      |      |           |          
- 300 |      |  0.5 |           |          
- 315 |      |      |        -1 |        -1
- 330 | -0.5 |      |           |          
- 345 |      |      |           |          
- 360 |    0 |    1 |         0 |  Infinity
-(25 rows)
+       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)
 
 SELECT x,
-       CASE WHEN asind(x) IN (-90,-30,0,30,90) THEN asind(x) END AS asind,
-       CASE WHEN acosd(x) IN (0,60,90,120,180) THEN acosd(x) END AS acosd,
-       CASE WHEN atand(x) IN (-45,0,45) THEN atand(x) END AS atand
+       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
 FROM (VALUES (-1), (-0.5), (0), (0.5), (1)) AS t(x);
-  x   | asind | acosd | atand 
-------+-------+-------+-------
-   -1 |   -90 |   180 |   -45
- -0.5 |   -30 |   120 |      
-    0 |     0 |    90 |     0
-  0.5 |    30 |    60 |      
-    1 |    90 |     0 |    45
+  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
 (5 rows)
 
-SELECT atand('-Infinity'::float8) = -90;
- ?column? 
-----------
- t
-(1 row)
-
-SELECT atand('Infinity'::float8) = 90;
- ?column? 
-----------
- t
-(1 row)
+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)
 
 SELECT x, y,
-       CASE WHEN atan2d(y, x) IN (-90,0,90,180) THEN atan2d(y, x) END AS atan2d
+       atan2d(y, x),
+       atan2d(y, x) IN (-90,0,90,180) AS atan2d_exact
 FROM (SELECT 10*cosd(a), 10*sind(a)
       FROM generate_series(0, 360, 90) AS t(a)) AS t(x,y);
-  x  |  y  | atan2d 
------+-----+--------
-  10 |   0 |      0
-   0 |  10 |     90
- -10 |   0 |    180
-   0 | -10 |    -90
-  10 |   0 |      0
+  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
 (5 rows)
 
+RESET extra_float_digits;
index 45a484b8b95b90a37987d56c580a05a87ad1333c..215e7a478499a1cebb91c19f571dfbdbbb7a29f8 100644 (file)
@@ -169,25 +169,47 @@ INSERT INTO FLOAT8_TBL(f1) VALUES ('-1.2345678901234e-200');
 SELECT '' AS five, * FROM FLOAT8_TBL;
 
 -- test exact cases for trigonometric functions in degrees
+SET extra_float_digits = 3;
+
+SELECT x,
+       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);
+
 SELECT x,
-       CASE WHEN sind(x) IN (-1,-0.5,0,0.5,1) THEN sind(x) END AS sind,
-       CASE WHEN cosd(x) IN (-1,-0.5,0,0.5,1) THEN cosd(x) END AS cosd,
-       CASE WHEN tand(x) IN ('-Infinity'::float8,-1,0,
-                             1,'Infinity'::float8) THEN tand(x) END AS tand,
-       CASE WHEN cotd(x) IN ('-Infinity'::float8,-1,0,
-                             1,'Infinity'::float8) THEN cotd(x) END AS cotd
-FROM generate_series(0, 360, 15) AS t(x);
+       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);
 
 SELECT x,
-       CASE WHEN asind(x) IN (-90,-30,0,30,90) THEN asind(x) END AS asind,
-       CASE WHEN acosd(x) IN (0,60,90,120,180) THEN acosd(x) END AS acosd,
-       CASE WHEN atand(x) IN (-45,0,45) THEN atand(x) END AS atand
+       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);
+
+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
 FROM (VALUES (-1), (-0.5), (0), (0.5), (1)) AS t(x);
 
-SELECT atand('-Infinity'::float8) = -90;
-SELECT atand('Infinity'::float8) = 90;
+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);
 
 SELECT x, y,
-       CASE WHEN atan2d(y, x) IN (-90,0,90,180) THEN atan2d(y, x) END AS atan2d
+       atan2d(y, x),
+       atan2d(y, x) IN (-90,0,90,180) AS atan2d_exact
 FROM (SELECT 10*cosd(a), 10*sind(a)
       FROM generate_series(0, 360, 90) AS t(a)) AS t(x,y);
+
+RESET extra_float_digits;