xref: /openbsd-src/gnu/usr.bin/perl/ext/POSIX/t/math.t (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1#!perl -w
2
3use strict;
4
5use POSIX;
6use Test::More;
7
8# These tests are mainly to make sure that these arithmetic functions
9# exist and are accessible.  They are not meant to be an exhaustive
10# test for the interface.
11
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
20is(acos(1), 0, "Basic acos(1) test");
21between(3.14, acos(-1), 3.15, 'acos(-1)');
22between(1.57, acos(0), 1.58, 'acos(0)');
23is(asin(0), 0, "Basic asin(0) test");
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)');
27is(atan(0), 0, "Basic atan(0) test");
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)');
31is(cosh(0), 1, "Basic cosh(0) test");
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)');
35is(floor(1.23441242), 1, "Basic floor(1.23441242) test");
36is(floor(-1.23441242), -2, "Basic floor(-1.23441242) test");
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");
44between(1.17, sinh(1), 1.18, 'sinh(1)');
45between(-1.18, sinh(-1), -1.17, 'sinh(-1)');
46is(tan(0), 0, "Basic tan(0) test");
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)');
50is(tanh(0), 0, "Basic tanh(0) test");
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();
56