summaryrefslogtreecommitdiff
path: root/t/op/exp.t
diff options
context:
space:
mode:
authorSteve Peters <steve@fisharerojo.org>2005-04-15 04:10:54 -0500
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2005-05-03 06:56:03 +0000
commit0630166f39b2fc31415e8078cd74fafef99606af (patch)
treebb0d2c7527f44450d12396bb9a75c887a7b08f38 /t/op/exp.t
parentc057f5bc3ae09d10fe8e5f8cc5afe4cca331e177 (diff)
downloadperl-0630166f39b2fc31415e8078cd74fafef99606af.tar.gz
IEEE math for the masses
Message-ID: <20050415141054.GA12749@mccoy.peters.homeunix.org> (tests added to t/op/exp.t) p4raw-id: //depot/perl@24371
Diffstat (limited to 't/op/exp.t')
-rwxr-xr-xt/op/exp.t34
1 files changed, 33 insertions, 1 deletions
diff --git a/t/op/exp.t b/t/op/exp.t
index 689f367b3f..927c5dadd8 100755
--- a/t/op/exp.t
+++ b/t/op/exp.t
@@ -6,7 +6,7 @@ BEGIN {
require './test.pl';
}
-plan tests => 6;
+plan tests => 22;
# compile time evaluation
@@ -29,3 +29,35 @@ $s = exp($x1);
is(substr($s,0,7), '2.71828');
ok(exp(log($x1)) == 1);
+
+# tests for transcendental functions
+
+my $pi = 3.1415926535897931160;
+my $pi_2 = 1.5707963267948965580;
+
+sub round {
+ my $result = shift;
+ return sprintf("%.9f", $result);
+}
+
+# sin() tests
+ok(sin(0) == 0.0);
+ok(round(sin($pi)) == 0.0);
+ok(round(sin(-1 * $pi)) == 0.0);
+ok(round(sin($pi_2)) == 1.0);
+ok(round(sin(-1 * $pi_2)) == -1.0);
+
+# cos() tests
+ok(cos(0) == 1.0);
+ok(round(cos($pi)) == -1.0);
+ok(round(cos(-1 * $pi)) == -1.0);
+ok(round(cos($pi_2)) == 0.0);
+ok(round(cos(-1 * $pi_2)) == 0.0);
+
+# atan2() tests
+ok(round(atan2(-0.0, 0.0)) == 0);
+ok(round(atan2(0.0, 0.0)) == 0);
+ok(round(atan2(-0.0, -0.0)) == round(-1 * $pi));
+ok(round(atan2(0.0, -0.0)) == round($pi));
+ok(round(atan2(-1.0, 0.0)) == round(-1 * $pi_2));
+ok(round(atan2(1.0, 0.0)) == round($pi_2));