Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
c057f5bc RGS |
3 | BEGIN { |
4 | chdir 't' if -d 't'; | |
5 | @INC = '../lib'; | |
6 | require './test.pl'; | |
7 | } | |
8d063cd8 | 8 | |
a1021d57 | 9 | plan tests => 16; |
8d063cd8 LW |
10 | |
11 | # compile time evaluation | |
12 | ||
13 | $s = sqrt(2); | |
e759bc31 | 14 | is(substr($s,0,5), '1.414', 'compile time sqrt(2) == 1.414'); |
8d063cd8 LW |
15 | |
16 | $s = exp(1); | |
e759bc31 | 17 | is(substr($s,0,7), '2.71828', 'compile time exp(1) == e'); |
8d063cd8 | 18 | |
e759bc31 | 19 | cmp_ok(exp(log(1)), '==', 1, 'compile time exp(log(1)) == 1'); |
8d063cd8 LW |
20 | |
21 | # run time evaluation | |
22 | ||
23 | $x1 = 1; | |
24 | $x2 = 2; | |
25 | $s = sqrt($x2); | |
e759bc31 | 26 | is(substr($s,0,5), '1.414', 'run time sqrt(2) == 1.414'); |
8d063cd8 LW |
27 | |
28 | $s = exp($x1); | |
e759bc31 | 29 | is(substr($s,0,7), '2.71828', 'run time exp(1) = e'); |
8d063cd8 | 30 | |
e759bc31 | 31 | cmp_ok(exp(log($x1)), '==', 1, 'run time exp(log(1)) == 1'); |
0630166f SP |
32 | |
33 | # tests for transcendental functions | |
34 | ||
35 | my $pi = 3.1415926535897931160; | |
36 | my $pi_2 = 1.5707963267948965580; | |
37 | ||
38 | sub round { | |
39 | my $result = shift; | |
40 | return sprintf("%.9f", $result); | |
41 | } | |
42 | ||
43 | # sin() tests | |
e759bc31 BE |
44 | cmp_ok(sin(0), '==', 0.0, 'sin(0) == 0'); |
45 | cmp_ok(round(sin($pi)), '==', 0.0, 'sin(pi) == 0'); | |
46 | cmp_ok(round(sin(-1 * $pi)), '==', 0.0, 'sin(-pi) == 0'); | |
47 | cmp_ok(round(sin($pi_2)), '==', 1.0, 'sin(pi/2) == 1'); | |
48 | cmp_ok(round(sin(-1 * $pi_2)), '==', -1.0, 'sin(-pi/2) == -1'); | |
0630166f SP |
49 | |
50 | # cos() tests | |
e759bc31 BE |
51 | cmp_ok(cos(0), '==', 1.0, 'cos(0) == 1'); |
52 | cmp_ok(round(cos($pi)), '==', -1.0, 'cos(pi) == -1'); | |
53 | cmp_ok(round(cos(-1 * $pi)), '==', -1.0, 'cos(-pi) == -1'); | |
54 | cmp_ok(round(cos($pi_2)), '==', 0.0, 'cos(pi/2) == 0'); | |
55 | cmp_ok(round(cos(-1 * $pi_2)), '==', 0.0, 'cos(-pi/2) == 0'); | |
0630166f | 56 | |
519bc777 RGS |
57 | # atan2() tests were removed due to differing results from calls to |
58 | # atan2() on various OS's and architectures. See perlport.pod for | |
59 | # more information. |