summaryrefslogtreecommitdiff
path: root/t/op/exp.t
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2014-08-30 21:14:12 -0400
committerJarkko Hietaniemi <jhi@iki.fi>2014-08-31 12:14:23 -0400
commit402bce5fcde176134b212beb8662ea0e2c5ce993 (patch)
tree059c66cb20d90c62a462b4d6649bae10d7310102 /t/op/exp.t
parentaf71714e5ef5109f8a41bdcfe59da43540fcd651 (diff)
downloadperl-402bce5fcde176134b212beb8662ea0e2c5ce993.tar.gz
Do not test sin/cos at [+-]pi, either.
With AIX and long doubles you may not get exactly the approximation of pi you were thinking of. "This is not the pi you are looking for".
Diffstat (limited to 't/op/exp.t')
-rw-r--r--t/op/exp.t22
1 files changed, 10 insertions, 12 deletions
diff --git a/t/op/exp.t b/t/op/exp.t
index a475502f78..f97b6d88f9 100644
--- a/t/op/exp.t
+++ b/t/op/exp.t
@@ -8,7 +8,7 @@ BEGIN {
require './test.pl';
}
-plan tests => 34;
+plan tests => 30;
# compile time evaluation
@@ -78,10 +78,12 @@ is(substr($s,0,5), '0.693', 'run time log(2)');
cmp_ok(exp(log($x1)), '==', 1, 'run time exp(log(1)) == 1');
-# tests for transcendental functions
+# NOTE: do NOT test the trigonometric functions at [+-]Pi
+# and expect to get exact results like 0, 1, -1, because
+# you may not be able to feed them exactly [+-]Pi given
+# all the variations of different long doubles.
-my $pi = 3.1415926535897931160;
-my $pi_2 = 1.5707963267948965580;
+my $pi_2 = 1.5707963267949;
sub round {
my $result = shift;
@@ -90,19 +92,15 @@ sub round {
# sin() tests
cmp_ok(sin(0), '==', 0.0, 'sin(0) == 0');
-cmp_ok(round(sin($pi)), '==', 0.0, 'sin(pi) == 0');
-cmp_ok(round(sin(-1 * $pi)), '==', 0.0, 'sin(-pi) == 0');
-cmp_ok(round(sin($pi_2)), '==', 1.0, 'sin(pi/2) == 1');
-cmp_ok(round(sin(-1 * $pi_2)), '==', -1.0, 'sin(-pi/2) == -1');
+cmp_ok(abs(sin($pi_2) - 1), '<', 1e-9, 'sin(pi/2) == 1');
+cmp_ok(abs(sin(-1 * $pi_2) - -1), '<', 1e-9, 'sin(-pi/2) == -1');
cmp_ok(round(sin($x1)), '==', '0.841470985', "sin(1)");
# cos() tests
cmp_ok(cos(0), '==', 1.0, 'cos(0) == 1');
-cmp_ok(round(cos($pi)), '==', -1.0, 'cos(pi) == -1');
-cmp_ok(round(cos(-1 * $pi)), '==', -1.0, 'cos(-pi) == -1');
-cmp_ok(round(cos($pi_2)), '==', 0.0, 'cos(pi/2) == 0');
-cmp_ok(round(cos(-1 * $pi_2)), '==', 0.0, 'cos(-pi/2) == 0');
+cmp_ok(abs(cos($pi_2)), '<', 1e-9, 'cos(pi/2) == 0');
+cmp_ok(abs(cos(-1 * $pi_2)), '<', 1e-9, 'cos(-pi/2) == 0');
cmp_ok(round(cos($x1)), '==', '0.540302306', "cos(1)");