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
20 use vars qw($x $y $z);
25 abs($_[0] - $_[1]) < (defined $_[2] ? $_[2] : $eps);
31 print 'not ' unless (near(tan($x), sin($x) / cos($x)));
34 print 'not ' unless (near(sinh(2), 3.62686040784702));
37 print 'not ' unless (near(acsch(0.1), 2.99822295029797));
41 print 'not ' unless (ref $x eq 'Math::Complex');
44 # avoid using Math::Complex here
45 $x =~ /^([^-]+)(-[^i]+)i$/;
47 print 'not ' unless (near($y, 1.5707963267949) and
48 near($z, -1.31695789692482));
51 print 'not ' unless (near(deg2rad(90), pi/2));
54 print 'not ' unless (near(rad2deg(pi), 180));
57 use Math::Trig ':radial';
60 my ($r,$t,$z) = cartesian_to_cylindrical(1,1,1);
62 print 'not ' unless (near($r, sqrt(2))) and
63 (near($t, deg2rad(45))) and
67 ($x,$y,$z) = cylindrical_to_cartesian($r, $t, $z);
69 print 'not ' unless (near($x, 1)) and
74 ($r,$t,$z) = cartesian_to_cylindrical(1,1,0);
76 print 'not ' unless (near($r, sqrt(2))) and
77 (near($t, deg2rad(45))) and
81 ($x,$y,$z) = cylindrical_to_cartesian($r, $t, $z);
83 print 'not ' unless (near($x, 1)) and
90 my ($r,$t,$f) = cartesian_to_spherical(1,1,1);
92 print 'not ' unless (near($r, sqrt(3))) and
93 (near($t, deg2rad(45))) and
94 (near($f, atan2(sqrt(2), 1)));
97 ($x,$y,$z) = spherical_to_cartesian($r, $t, $f);
99 print 'not ' unless (near($x, 1)) and
104 ($r,$t,$f) = cartesian_to_spherical(1,1,0);
106 print 'not ' unless (near($r, sqrt(2))) and
107 (near($t, deg2rad(45))) and
108 (near($f, deg2rad(90)));
111 ($x,$y,$z) = spherical_to_cartesian($r, $t, $f);
113 print 'not ' unless (near($x, 1)) and
120 my ($r,$t,$z) = cylindrical_to_spherical(spherical_to_cylindrical(1,1,1));
122 print 'not ' unless (near($r, 1)) and
127 ($r,$t,$z) = spherical_to_cylindrical(cylindrical_to_spherical(1,1,1));
129 print 'not ' unless (near($r, 1)) and
136 use Math::Trig 'great_circle_distance';
139 unless (near(great_circle_distance(0, 0, 0, pi/2), pi/2));
143 unless (near(great_circle_distance(0, 0, pi, pi), pi));
147 my @L = (deg2rad(-0.5), deg2rad(90 - 51.3));
148 my @T = (deg2rad(139.8),deg2rad(90 - 35.7));
150 my $km = great_circle_distance(@L, @T, 6378);
152 print 'not ' unless (near($km, 9605.26637021388));