BEGIN {
chdir 't' if -d 't';
- unshift @INC, '../lib';
+ @INC = '../lib';
}
use Math::Trig;
}
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..24\n";
+print "1..26\n";
$x = 0.9;
print 'not ' unless (near(tan($x), sin($x) / cos($x)));
}
{
+ my $R2D = 57.295779513082320876798154814169;
+
+ sub frac { $_[0] - int($_[0]) }
+
my $lotta_radians = deg2rad(1E+20, 1);
- print "not " unless near($lotta_radians, 1E+20/57.29577951308232087721);
+ 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*57.29577951308232087721);
+ 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*57.29577951308232087721);
-
+ print "not " unless near($posit_degrees, -10000*$R2D);
print "ok 23\n";
+}
- my $posiu_degrees = rad2deg(-10000, 0);
- print "not " unless near($posiu_degrees, -197.795130823273);
+{
+ use Math::Trig 'great_circle_direction';
+ print 'not '
+ unless (near(great_circle_direction(0, 0, 0, pi/2), pi));
print "ok 24\n";
+
+ print 'not '
+ unless (near(great_circle_direction(0, 0, pi, pi), -pi()/2));
+ print "ok 25\n";
+
+ # London to Tokyo.
+ my @L = (deg2rad(-0.5), deg2rad(90 - 51.3));
+ my @T = (deg2rad(139.8),deg2rad(90 - 35.7));
+
+ my $rad = great_circle_direction(@L, @T);
+
+ print 'not ' unless (near($rad, -0.546644569997376));
+ print "ok 26\n";
}
# eof