4 # Regression tests for the Math::Trig package
6 # The tests are quite modest as the Math::Complex tests exercise
7 # these quite vigorously.
9 # -- Jarkko Hietaniemi, April 1997
13 unshift @INC, '../lib';
20 use vars qw($x $y $z);
24 if ($^O eq 'unicos') { # See lib/Math/Complex.pm and t/lib/complex.t.
29 abs($_[0] - $_[1]) < (defined $_[2] ? $_[2] : $eps);
35 print 'not ' unless (near(tan($x), sin($x) / cos($x)));
38 print 'not ' unless (near(sinh(2), 3.62686040784702));
41 print 'not ' unless (near(acsch(0.1), 2.99822295029797));
45 print 'not ' unless (ref $x eq 'Math::Complex');
48 # avoid using Math::Complex here
49 $x =~ /^([^-]+)(-[^i]+)i$/;
51 print 'not ' unless (near($y, 1.5707963267949) and
52 near($z, -1.31695789692482));
55 print 'not ' unless (near(deg2rad(90), pi/2));
58 print 'not ' unless (near(rad2deg(pi), 180));
61 use Math::Trig ':radial';
64 my ($r,$t,$z) = cartesian_to_cylindrical(1,1,1);
66 print 'not ' unless (near($r, sqrt(2))) and
67 (near($t, deg2rad(45))) and
71 ($x,$y,$z) = cylindrical_to_cartesian($r, $t, $z);
73 print 'not ' unless (near($x, 1)) and
78 ($r,$t,$z) = cartesian_to_cylindrical(1,1,0);
80 print 'not ' unless (near($r, sqrt(2))) and
81 (near($t, deg2rad(45))) and
85 ($x,$y,$z) = cylindrical_to_cartesian($r, $t, $z);
87 print 'not ' unless (near($x, 1)) and
94 my ($r,$t,$f) = cartesian_to_spherical(1,1,1);
96 print 'not ' unless (near($r, sqrt(3))) and
97 (near($t, deg2rad(45))) and
98 (near($f, atan2(sqrt(2), 1)));
101 ($x,$y,$z) = spherical_to_cartesian($r, $t, $f);
103 print 'not ' unless (near($x, 1)) and
108 ($r,$t,$f) = cartesian_to_spherical(1,1,0);
110 print 'not ' unless (near($r, sqrt(2))) and
111 (near($t, deg2rad(45))) and
112 (near($f, deg2rad(90)));
115 ($x,$y,$z) = spherical_to_cartesian($r, $t, $f);
117 print 'not ' unless (near($x, 1)) and
124 my ($r,$t,$z) = cylindrical_to_spherical(spherical_to_cylindrical(1,1,1));
126 print 'not ' unless (near($r, 1)) and
131 ($r,$t,$z) = spherical_to_cylindrical(cylindrical_to_spherical(1,1,1));
133 print 'not ' unless (near($r, 1)) and
140 use Math::Trig 'great_circle_distance';
143 unless (near(great_circle_distance(0, 0, 0, pi/2), pi/2));
147 unless (near(great_circle_distance(0, 0, pi, pi), pi));
151 my @L = (deg2rad(-0.5), deg2rad(90 - 51.3));
152 my @T = (deg2rad(139.8),deg2rad(90 - 35.7));
154 my $km = great_circle_distance(@L, @T, 6378);
156 print 'not ' unless (near($km, 9605.26637021388));