Commit | Line | Data |
---|---|---|
867bef19 SP |
1 | #!perl -w |
2 | ||
3 | use strict; | |
4 | ||
5 | use POSIX; | |
1a77755a | 6 | use Test::More; |
867bef19 | 7 | |
1a917639 JH |
8 | use Config; |
9 | ||
b7b1e41b | 10 | # These tests are mainly to make sure that these arithmetic functions |
867bef19 SP |
11 | # exist and are accessible. They are not meant to be an exhaustive |
12 | # test for the interface. | |
13 | ||
1a77755a NC |
14 | sub between { |
15 | my ($low, $have, $high, $desc) = @_; | |
16 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |
17 | ||
18 | cmp_ok($have, '>=', $low, $desc); | |
19 | cmp_ok($have, '<=', $high, $desc); | |
20 | } | |
21 | ||
867bef19 | 22 | is(acos(1), 0, "Basic acos(1) test"); |
1a77755a NC |
23 | between(3.14, acos(-1), 3.15, 'acos(-1)'); |
24 | between(1.57, acos(0), 1.58, 'acos(0)'); | |
867bef19 | 25 | is(asin(0), 0, "Basic asin(0) test"); |
1a77755a NC |
26 | cmp_ok(asin(1), '>', 1.57, "Basic asin(1) test"); |
27 | cmp_ok(asin(-1), '<', -1.57, "Basic asin(-1) test"); | |
28 | cmp_ok(asin(1), '==', -asin(-1), 'asin(1) == -asin(-1)'); | |
867bef19 | 29 | is(atan(0), 0, "Basic atan(0) test"); |
1a77755a NC |
30 | between(0.785, atan(1), 0.786, 'atan(1)'); |
31 | between(-0.786, atan(-1), -0.785, 'atan(-1)'); | |
32 | cmp_ok(atan(1), '==', -atan(-1), 'atan(1) == -atan(-1)'); | |
867bef19 | 33 | is(cosh(0), 1, "Basic cosh(0) test"); |
1a77755a NC |
34 | between(1.54, cosh(1), 1.55, 'cosh(1)'); |
35 | between(1.54, cosh(-1), 1.55, 'cosh(-1)'); | |
36 | is(cosh(1), cosh(-1), 'cosh(1) == cosh(-1)'); | |
867bef19 | 37 | is(floor(1.23441242), 1, "Basic floor(1.23441242) test"); |
1a77755a | 38 | is(floor(-1.23441242), -2, "Basic floor(-1.23441242) test"); |
867bef19 SP |
39 | is(fmod(3.5, 2.0), 1.5, "Basic fmod(3.5, 2.0) test"); |
40 | is(join(" ", frexp(1)), "0.5 1", "Basic frexp(1) test"); | |
41 | is(ldexp(0,1), 0, "Basic ldexp(0,1) test"); | |
42 | is(log10(1), 0, "Basic log10(1) test"); | |
43 | is(log10(10), 1, "Basic log10(10) test"); | |
44 | is(join(" ", modf(1.76)), "0.76 1", "Basic modf(1.76) test"); | |
45 | is(sinh(0), 0, "Basic sinh(0) test"); | |
1a77755a NC |
46 | between(1.17, sinh(1), 1.18, 'sinh(1)'); |
47 | between(-1.18, sinh(-1), -1.17, 'sinh(-1)'); | |
867bef19 | 48 | is(tan(0), 0, "Basic tan(0) test"); |
1a77755a NC |
49 | between(1.55, tan(1), 1.56, 'tan(1)'); |
50 | between(1.55, tan(1), 1.56, 'tan(-1)'); | |
51 | cmp_ok(tan(1), '==', -tan(-1), 'tan(1) == -tan(-1)'); | |
867bef19 | 52 | is(tanh(0), 0, "Basic tanh(0) test"); |
1a77755a NC |
53 | between(0.76, tanh(1), 0.77, 'tanh(1)'); |
54 | between(-0.77, tanh(-1), -0.76, 'tanh(-1)'); | |
55 | cmp_ok(tanh(1), '==', -tanh(-1), 'tanh(1) == -tanh(-1)'); | |
56 | ||
1a917639 JH |
57 | cmp_ok(abs(M_PI - 3.14159265358979), '<', 1e9, "M_PI"); |
58 | cmp_ok(abs(asinh(1) - 0.881373587019543), '<', 1e9, "asinh"); | |
59 | cmp_ok(abs(cbrt(8) - 2), '<', 1e9, "cbrt"); | |
60 | is(copysign(3.14, -2), -3.14, "copysign"); | |
61 | cmp_ok(abs(expm1(2) - 6.38905609893065), '<', 1e9, "expm1"); | |
62 | SKIP: { | |
63 | unless ($Config{d_fpclassify}) { | |
64 | skip 4, "no fpclassify"; | |
65 | } | |
66 | is(fpclassify(1), FP_NORMAL, "fpclassify 1"); | |
67 | is(fpclassify(0), FP_ZERO, "fpclassify 0"); | |
68 | is(fpclassify(INFINITY), FP_INFINITE, "fpclassify Inf"); | |
69 | is(fpclassify(NAN), FP_NAN, "fpclassify NAN"); | |
70 | } | |
71 | SKIP: { | |
72 | unless ($Config{d_isfinite}) { | |
73 | skip 1, "no isfinite"; | |
74 | } | |
75 | ok(isfinite(1), "isfinite"); | |
76 | } | |
77 | SKIP: { | |
78 | unless ($Config{d_isinf}) { | |
79 | skip 1, "no isinf"; | |
80 | } | |
81 | ok(isinf(INFINITY), "isinf"); | |
82 | } | |
83 | SKIP: { | |
84 | unless ($Config{d_isnan}) { | |
85 | skip 1, "no isnan"; | |
86 | } | |
87 | ok(isnan(NAN), "isnan"); | |
88 | } | |
89 | cmp_ok(abs(log1p(2) - 1.09861228866811), '<', 1e9, "log1p"); | |
90 | cmp_ok(abs(log2(8) - 3), '<', 1e9, "log2"); | |
91 | SKIP: { | |
92 | unless ($Config{d_signbit}) { | |
93 | skip 2, "no signbit"; | |
94 | } | |
95 | is(signbit(2), 0, "signbit 2"); | |
96 | is(signbit(-2), 1, "signbit -2"); | |
97 | } | |
98 | is(round(2.25), 2, "round 2.25"); | |
99 | is(round(-2.25), -2, "round -2.25"); | |
100 | is(round(2.5), 3, "round 2.5"); | |
101 | is(round(-2.5), -3, "round -2.5"); | |
102 | is(round(2.75), 3, "round 2.75"); | |
103 | is(round(-2.75), -3, "round 2.75"); | |
104 | is(trunc(2.25), 2, "trunc 2.25"); | |
105 | is(trunc(-2.25), -2, "trunc -2.25"); | |
106 | is(trunc(2.5), 2, "trunc 2.5"); | |
107 | is(trunc(-2.5), -2, "trunc -2.5"); | |
108 | is(trunc(2.75), 2, "trunc 2.75"); | |
109 | is(trunc(-2.75), -2, "trunc -2.75"); | |
110 | ||
1a77755a | 111 | done_testing(); |