Commit | Line | Data |
5aabfad6 |
1 | #!./perl |
2 | |
3 | # |
4 | # Regression tests for the Math::Trig package |
5 | # |
6 | # The tests are quite modest as the Math::Complex tests exercise |
7 | # these quite vigorously. |
8 | # |
9 | # -- Jarkko Hietaniemi, April 1997 |
10 | |
11 | BEGIN { |
12 | chdir 't' if -d 't'; |
13 | @INC = '../lib'; |
14 | } |
15 | |
16 | use Math::Trig; |
17 | |
18 | use strict; |
19 | |
20 | use vars qw($x $y $z); |
21 | |
22 | my $eps = 1e-11; |
23 | |
24 | sub near ($$;$) { |
25 | abs($_[0] - $_[1]) < (defined $_[2] ? $_[2] : $eps); |
26 | } |
27 | |
28 | print "1..6\n"; |
29 | |
30 | $x = 0.9; |
31 | print 'not ' unless (near(tan($x), sin($x) / cos($x))); |
32 | print "ok 1\n"; |
33 | |
34 | print 'not ' unless (near(sinh(2), 3.62686040784702)); |
35 | print "ok 2\n"; |
36 | |
37 | print 'not ' unless (near(acsch(0.1), 2.99822295029797)); |
38 | print "ok 3\n"; |
39 | |
40 | $x = asin(2); |
41 | print 'not ' unless (ref $x eq 'Math::Complex'); |
42 | print "ok 4\n"; |
43 | |
44 | # avoid using Math::Complex here |
45 | $x =~ /^([^-]+)(-[^i]+)i$/; |
46 | ($y, $z) = ($1, $2); |
47 | print 'not ' unless (near($y, 1.5707963267949) and |
48 | near($z, -1.31695789692482)); |
49 | print "ok 5\n"; |
50 | |
51 | print 'not ' unless (near(deg_to_rad(90), pi/2)); |
52 | print "ok 6\n"; |
53 | |
54 | # eof |