This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
POSIX math: Hopefully better use of Configure symbols.
[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
b7b1e41b 8# These tests are mainly to make sure that these arithmetic functions
867bef19
SP
9# exist and are accessible. They are not meant to be an exhaustive
10# test for the interface.
11
1a77755a
NC
12sub between {
13 my ($low, $have, $high, $desc) = @_;
14 local $Test::Builder::Level = $Test::Builder::Level + 1;
15
16 cmp_ok($have, '>=', $low, $desc);
17 cmp_ok($have, '<=', $high, $desc);
18}
19
867bef19 20is(acos(1), 0, "Basic acos(1) test");
1a77755a
NC
21between(3.14, acos(-1), 3.15, 'acos(-1)');
22between(1.57, acos(0), 1.58, 'acos(0)');
867bef19 23is(asin(0), 0, "Basic asin(0) test");
1a77755a
NC
24cmp_ok(asin(1), '>', 1.57, "Basic asin(1) test");
25cmp_ok(asin(-1), '<', -1.57, "Basic asin(-1) test");
26cmp_ok(asin(1), '==', -asin(-1), 'asin(1) == -asin(-1)');
867bef19 27is(atan(0), 0, "Basic atan(0) test");
1a77755a
NC
28between(0.785, atan(1), 0.786, 'atan(1)');
29between(-0.786, atan(-1), -0.785, 'atan(-1)');
30cmp_ok(atan(1), '==', -atan(-1), 'atan(1) == -atan(-1)');
867bef19 31is(cosh(0), 1, "Basic cosh(0) test");
1a77755a
NC
32between(1.54, cosh(1), 1.55, 'cosh(1)');
33between(1.54, cosh(-1), 1.55, 'cosh(-1)');
34is(cosh(1), cosh(-1), 'cosh(1) == cosh(-1)');
867bef19 35is(floor(1.23441242), 1, "Basic floor(1.23441242) test");
1a77755a 36is(floor(-1.23441242), -2, "Basic floor(-1.23441242) test");
867bef19
SP
37is(fmod(3.5, 2.0), 1.5, "Basic fmod(3.5, 2.0) test");
38is(join(" ", frexp(1)), "0.5 1", "Basic frexp(1) test");
39is(ldexp(0,1), 0, "Basic ldexp(0,1) test");
40is(log10(1), 0, "Basic log10(1) test");
41is(log10(10), 1, "Basic log10(10) test");
42is(join(" ", modf(1.76)), "0.76 1", "Basic modf(1.76) test");
43is(sinh(0), 0, "Basic sinh(0) test");
1a77755a
NC
44between(1.17, sinh(1), 1.18, 'sinh(1)');
45between(-1.18, sinh(-1), -1.17, 'sinh(-1)');
867bef19 46is(tan(0), 0, "Basic tan(0) test");
1a77755a
NC
47between(1.55, tan(1), 1.56, 'tan(1)');
48between(1.55, tan(1), 1.56, 'tan(-1)');
49cmp_ok(tan(1), '==', -tan(-1), 'tan(1) == -tan(-1)');
867bef19 50is(tanh(0), 0, "Basic tanh(0) test");
1a77755a
NC
51between(0.76, tanh(1), 0.77, 'tanh(1)');
52between(-0.77, tanh(-1), -0.76, 'tanh(-1)');
53cmp_ok(tanh(1), '==', -tanh(-1), 'tanh(1) == -tanh(-1)');
54
55done_testing();