This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
POSIX math: Configure scan for acosh.
[perl5.git] / ext / POSIX / t / math.t
CommitLineData
867bef19
SP
1#!perl -w
2
3use strict;
4
5use POSIX;
1a77755a 6use Test::More;
867bef19 7
1a917639
JH
8use 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
14sub 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 22is(acos(1), 0, "Basic acos(1) test");
1a77755a
NC
23between(3.14, acos(-1), 3.15, 'acos(-1)');
24between(1.57, acos(0), 1.58, 'acos(0)');
867bef19 25is(asin(0), 0, "Basic asin(0) test");
1a77755a
NC
26cmp_ok(asin(1), '>', 1.57, "Basic asin(1) test");
27cmp_ok(asin(-1), '<', -1.57, "Basic asin(-1) test");
28cmp_ok(asin(1), '==', -asin(-1), 'asin(1) == -asin(-1)');
867bef19 29is(atan(0), 0, "Basic atan(0) test");
1a77755a
NC
30between(0.785, atan(1), 0.786, 'atan(1)');
31between(-0.786, atan(-1), -0.785, 'atan(-1)');
32cmp_ok(atan(1), '==', -atan(-1), 'atan(1) == -atan(-1)');
867bef19 33is(cosh(0), 1, "Basic cosh(0) test");
1a77755a
NC
34between(1.54, cosh(1), 1.55, 'cosh(1)');
35between(1.54, cosh(-1), 1.55, 'cosh(-1)');
36is(cosh(1), cosh(-1), 'cosh(1) == cosh(-1)');
867bef19 37is(floor(1.23441242), 1, "Basic floor(1.23441242) test");
1a77755a 38is(floor(-1.23441242), -2, "Basic floor(-1.23441242) test");
867bef19
SP
39is(fmod(3.5, 2.0), 1.5, "Basic fmod(3.5, 2.0) test");
40is(join(" ", frexp(1)), "0.5 1", "Basic frexp(1) test");
41is(ldexp(0,1), 0, "Basic ldexp(0,1) test");
42is(log10(1), 0, "Basic log10(1) test");
43is(log10(10), 1, "Basic log10(10) test");
44is(join(" ", modf(1.76)), "0.76 1", "Basic modf(1.76) test");
45is(sinh(0), 0, "Basic sinh(0) test");
1a77755a
NC
46between(1.17, sinh(1), 1.18, 'sinh(1)');
47between(-1.18, sinh(-1), -1.17, 'sinh(-1)');
867bef19 48is(tan(0), 0, "Basic tan(0) test");
1a77755a
NC
49between(1.55, tan(1), 1.56, 'tan(1)');
50between(1.55, tan(1), 1.56, 'tan(-1)');
51cmp_ok(tan(1), '==', -tan(-1), 'tan(1) == -tan(-1)');
867bef19 52is(tanh(0), 0, "Basic tanh(0) test");
1a77755a
NC
53between(0.76, tanh(1), 0.77, 'tanh(1)');
54between(-0.77, tanh(-1), -0.76, 'tanh(-1)');
55cmp_ok(tanh(1), '==', -tanh(-1), 'tanh(1) == -tanh(-1)');
56
1a917639
JH
57cmp_ok(abs(M_PI - 3.14159265358979), '<', 1e9, "M_PI");
58cmp_ok(abs(asinh(1) - 0.881373587019543), '<', 1e9, "asinh");
59cmp_ok(abs(cbrt(8) - 2), '<', 1e9, "cbrt");
60is(copysign(3.14, -2), -3.14, "copysign");
61cmp_ok(abs(expm1(2) - 6.38905609893065), '<', 1e9, "expm1");
62SKIP: {
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}
71SKIP: {
72 unless ($Config{d_isfinite}) {
73 skip 1, "no isfinite";
74 }
75 ok(isfinite(1), "isfinite");
76}
77SKIP: {
78 unless ($Config{d_isinf}) {
79 skip 1, "no isinf";
80 }
81 ok(isinf(INFINITY), "isinf");
82}
83SKIP: {
84 unless ($Config{d_isnan}) {
85 skip 1, "no isnan";
86 }
87 ok(isnan(NAN), "isnan");
88}
89cmp_ok(abs(log1p(2) - 1.09861228866811), '<', 1e9, "log1p");
90cmp_ok(abs(log2(8) - 3), '<', 1e9, "log2");
91SKIP: {
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}
98is(round(2.25), 2, "round 2.25");
99is(round(-2.25), -2, "round -2.25");
100is(round(2.5), 3, "round 2.5");
101is(round(-2.5), -3, "round -2.5");
102is(round(2.75), 3, "round 2.75");
103is(round(-2.75), -3, "round 2.75");
104is(trunc(2.25), 2, "trunc 2.25");
105is(trunc(-2.25), -2, "trunc -2.25");
106is(trunc(2.5), 2, "trunc 2.5");
107is(trunc(-2.5), -2, "trunc -2.5");
108is(trunc(2.75), 2, "trunc 2.75");
109is(trunc(-2.75), -2, "trunc -2.75");
110
1a77755a 111done_testing();