Upgrade to Math-Complex-1.43
[p5sagit/p5-mst-13.2.git] / lib / Math / Trig.t
index 65bb796..b05e636 100755 (executable)
@@ -26,9 +26,10 @@ BEGIN {
     }
 }
 
-plan(tests => 69);
+plan(tests => 135);
 
-use Math::Trig 1.03;
+use Math::Trig 1.08;
+use Math::Trig 1.08 qw(Inf);
 
 my $pip2 = pi / 2;
 
@@ -49,6 +50,42 @@ sub near ($$;$) {
     $_[1] ? ($d < $e) : abs($_[0]) < $e;
 }
 
+print "# Sanity checks\n";
+
+ok(near(sin(1), 0.841470984807897));
+ok(near(cos(1), 0.54030230586814));
+ok(near(tan(1), 1.5574077246549));
+
+ok(near(sec(1), 1.85081571768093));
+ok(near(csc(1), 1.18839510577812));
+ok(near(cot(1), 0.642092615934331));
+
+ok(near(asin(1), 1.5707963267949));
+ok(near(acos(1), 0));
+ok(near(atan(1), 0.785398163397448));
+
+ok(near(asec(1), 0));
+ok(near(acsc(1), 1.5707963267949));
+ok(near(acot(1), 0.785398163397448));
+
+ok(near(sinh(1), 1.1752011936438));
+ok(near(cosh(1), 1.54308063481524));
+ok(near(tanh(1), 0.761594155955765));
+
+ok(near(sech(1), 0.648054273663885));
+ok(near(csch(1), 0.850918128239322));
+ok(near(coth(1), 1.31303528549933));
+
+ok(near(asinh(1), 0.881373587019543));
+ok(near(acosh(1), 0));
+ok(near(atanh(0.9), 1.47221948958322)); # atanh(1.0) would be an error.
+
+ok(near(asech(0.9), 0.467145308103262));
+ok(near(acsch(2), 0.481211825059603));
+ok(near(acoth(2), 0.549306144334055));
+
+print "# Basics\n";
+
 $x = 0.9;
 ok(near(tan($x), sin($x) / cos($x)));
 
@@ -145,8 +182,8 @@ use Math::Trig ':radial';
     ok(near(great_circle_distance(0, 0, pi, pi), pi));
 
     # London to Tokyo.
-    my @L = (deg2rad(-0.5), deg2rad(90 - 51.3));
-    my @T = (deg2rad(139.8),deg2rad(90 - 35.7));
+    my @L = (deg2rad(-0.5),  deg2rad(90 - 51.3));
+    my @T = (deg2rad(139.8), deg2rad(90 - 35.7));
 
     my $km = great_circle_distance(@L, @T, 6378);
 
@@ -207,37 +244,37 @@ use Math::Trig ':radial';
 
     ok(near($lon, $London[0]));
 
-    ok(near($lat, $pip2 - $London[1]));
+    ok(near($lat, $London[1]));
 
     ($lon, $lat) = great_circle_waypoint(@London, @Tokyo, 1.0);
 
     ok(near($lon, $Tokyo[0]));
 
-    ok(near($lat, $pip2 - $Tokyo[1]));
+    ok(near($lat, $Tokyo[1]));
 
     ($lon, $lat) = great_circle_waypoint(@London, @Tokyo, 0.5);
 
-    ok(near($lon, 1.55609593577679)); # 89.1577 E
+    ok(near($lon, 1.55609593577679)); # 89.16 E
 
-    ok(near($lat, 1.20296099733328)); # 68.9246 N
+    ok(near($lat, 0.36783532946162)); # 68.93 N
 
     ($lon, $lat) = great_circle_midpoint(@London, @Tokyo);
 
-    ok(near($lon, 1.55609593577679)); # 89.1577 E
+    ok(near($lon, 1.55609593577679)); # 89.16 E
 
-    ok(near($lat, 1.20296099733328)); # 68.9246 N
+    ok(near($lat, 0.367835329461615)); # 68.93 N
 
     ($lon, $lat) = great_circle_waypoint(@London, @Tokyo, 0.25);
 
-    ok(near($lon, 0.516073562850837)); # 29.5688 E
+    ok(near($lon, 0.516073562850837)); # 29.57 E
 
-    ok(near($lat, 1.170565013391510)); # 67.0684 N
+    ok(near($lat, 0.400231313403387)); # 67.07 N
 
     ($lon, $lat) = great_circle_waypoint(@London, @Tokyo, 0.75);
 
-    ok(near($lon, 2.17494903805952)); # 124.6154 E
+    ok(near($lon, 2.17494903805952)); # 124.62 E
 
-    ok(near($lat, 0.952987032741305)); # 54.6021 N
+    ok(near($lat, 0.617809294053591)); # 54.60 N
 
     use Math::Trig 'great_circle_destination';
 
@@ -270,4 +307,58 @@ use Math::Trig ':radial';
     ok(near($dst1, $dst2));
 }
 
+print "# Infinity\n";
+
+my $BigDouble = 1e40;
+
+ok(Inf() > $BigDouble);
+ok(Inf() + $BigDouble > $BigDouble);
+ok(Inf() + $BigDouble == Inf());
+ok(Inf() - $BigDouble > $BigDouble);
+ok(Inf() - $BigDouble == Inf());
+ok(Inf() * $BigDouble > $BigDouble);
+ok(Inf() * $BigDouble == Inf());
+ok(Inf() / $BigDouble > $BigDouble);
+ok(Inf() / $BigDouble == Inf());
+
+ok(-Inf() < -$BigDouble);
+ok(-Inf() + $BigDouble < $BigDouble);
+ok(-Inf() + $BigDouble == -Inf());
+ok(-Inf() - $BigDouble < -$BigDouble);
+ok(-Inf() - $BigDouble == -Inf());
+ok(-Inf() * $BigDouble < -$BigDouble);
+ok(-Inf() * $BigDouble == -Inf());
+ok(-Inf() / $BigDouble < -$BigDouble);
+ok(-Inf() / $BigDouble == -Inf());
+
+print "# sinh/sech/cosh/csch/tanh/coth unto infinity\n";
+
+ok(near(sinh(100), 1.3441e+43, 1e-3));
+ok(near(sech(100), 7.4402e-44, 1e-3));
+ok(near(cosh(100), 1.3441e+43, 1e-3));
+ok(near(csch(100), 7.4402e-44, 1e-3));
+ok(near(tanh(100), 1));
+ok(near(coth(100), 1));
+
+ok(near(sinh(-100), -1.3441e+43, 1e-3));
+ok(near(sech(-100),  7.4402e-44, 1e-3));
+ok(near(cosh(-100),  1.3441e+43, 1e-3));
+ok(near(csch(-100), -7.4402e-44, 1e-3));
+ok(near(tanh(-100), -1));
+ok(near(coth(-100), -1));
+
+cmp_ok(sinh(1e5), '==', Inf());
+cmp_ok(sech(1e5), '==', 0);
+cmp_ok(cosh(1e5), '==', Inf());
+cmp_ok(csch(1e5), '==', 0);
+cmp_ok(tanh(1e5), '==', 1);
+cmp_ok(coth(1e5), '==', 1);
+
+cmp_ok(sinh(-1e5), '==', -Inf());
+cmp_ok(sech(-1e5), '==', 0);
+cmp_ok(cosh(-1e5), '==', Inf());
+cmp_ok(csch(-1e5), '==', 0);
+cmp_ok(tanh(-1e5), '==', -1);
+cmp_ok(coth(-1e5), '==', -1);
+
 # eof