This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[inseparable changes from match from perl-5.003_97 to perl-5.003_97a]
[perl5.git] / t / lib / trig.t
CommitLineData
5aabfad6
PP
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
11BEGIN {
12 chdir 't' if -d 't';
13 @INC = '../lib';
14}
15
16use Math::Trig;
17
18use strict;
19
20use vars qw($x $y $z);
21
22my $eps = 1e-11;
23
24sub near ($$;$) {
25 abs($_[0] - $_[1]) < (defined $_[2] ? $_[2] : $eps);
26}
27
28print "1..6\n";
29
30$x = 0.9;
31print 'not ' unless (near(tan($x), sin($x) / cos($x)));
32print "ok 1\n";
33
34print 'not ' unless (near(sinh(2), 3.62686040784702));
35print "ok 2\n";
36
37print 'not ' unless (near(acsch(0.1), 2.99822295029797));
38print "ok 3\n";
39
40$x = asin(2);
41print 'not ' unless (ref $x eq 'Math::Complex');
42print "ok 4\n";
43
44# avoid using Math::Complex here
45$x =~ /^([^-]+)(-[^i]+)i$/;
46($y, $z) = ($1, $2);
47print 'not ' unless (near($y, 1.5707963267949) and
48 near($z, -1.31695789692482));
49print "ok 5\n";
50
51print 'not ' unless (near(deg_to_rad(90), pi/2));
52print "ok 6\n";
53
54# eof