summaryrefslogtreecommitdiff
path: root/t/lib/trig.t
diff options
context:
space:
mode:
Diffstat (limited to 't/lib/trig.t')
-rwxr-xr-xt/lib/trig.t51
1 files changed, 35 insertions, 16 deletions
diff --git a/t/lib/trig.t b/t/lib/trig.t
index 20669f0bd9..6949622f0a 100755
--- a/t/lib/trig.t
+++ b/t/lib/trig.t
@@ -10,7 +10,7 @@
BEGIN {
chdir 't' if -d 't';
- unshift @INC, '../lib';
+ @INC = '../lib';
}
use Math::Trig;
@@ -26,10 +26,11 @@ if ($^O eq 'unicos') { # See lib/Math/Complex.pm and t/lib/complex.t.
}
sub near ($$;$) {
- abs($_[0] - $_[1]) < (defined $_[2] ? $_[2] : $eps);
+ my $e = defined $_[2] ? $_[2] : $eps;
+ $_[1] ? (abs($_[0]/$_[1] - 1) < $e) : abs($_[0]) < $e;
}
-print "1..20\n";
+print "1..23\n";
$x = 0.9;
print 'not ' unless (near(tan($x), sin($x) / cos($x)));
@@ -137,24 +138,42 @@ use Math::Trig ':radial';
}
{
- use Math::Trig 'great_circle_distance';
+ use Math::Trig 'great_circle_distance';
- print 'not '
- unless (near(great_circle_distance(0, 0, 0, pi/2), pi/2));
- print "ok 18\n";
+ print 'not '
+ unless (near(great_circle_distance(0, 0, 0, pi/2), pi/2));
+ print "ok 18\n";
- print 'not '
- unless (near(great_circle_distance(0, 0, pi, pi), pi));
- print "ok 19\n";
+ print 'not '
+ unless (near(great_circle_distance(0, 0, pi, pi), pi));
+ print "ok 19\n";
- # London to Tokyo.
- my @L = (deg2rad(-0.5), deg2rad(90 - 51.3));
- my @T = (deg2rad(139.8),deg2rad(90 - 35.7));
+ # London to Tokyo.
+ 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);
+ my $km = great_circle_distance(@L, @T, 6378);
- print 'not ' unless (near($km, 9605.26637021388));
- print "ok 20\n";
+ print 'not ' unless (near($km, 9605.26637021388));
+ print "ok 20\n";
+}
+
+{
+ my $R2D = 57.295779513082320876798154814169;
+
+ sub frac { $_[0] - int($_[0]) }
+
+ my $lotta_radians = deg2rad(1E+20, 1);
+ print "not " unless near($lotta_radians, 1E+20/$R2D);
+ print "ok 21\n";
+
+ my $negat_degrees = rad2deg(-1E20, 1);
+ print "not " unless near($negat_degrees, -1E+20*$R2D);
+ print "ok 22\n";
+
+ my $posit_degrees = rad2deg(-10000, 1);
+ print "not " unless near($posit_degrees, -10000*$R2D);
+ print "ok 23\n";
}
# eof