| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use strict; |
| 4 | use warnings; |
| 5 | use sigtrap qw(die normal-signals error-signals); |
| 6 | |
| 7 | use Config; |
| 8 | use Test::More tests => 43; |
| 9 | |
| 10 | use POSIX::2008; |
| 11 | |
| 12 | sub _cmp_between { |
| 13 | my ($lower, $value, $upper, $desc) = @_; |
| 14 | local $Test::Builder::Level = $Test::Builder::Level + 1; |
| 15 | |
| 16 | cmp_ok($lower, '<', $value, $desc); |
| 17 | cmp_ok($value, '<', $upper, $desc); |
| 18 | } |
| 19 | |
| 20 | # is_deeply() fails to compare 0.0 == -0.0 |
| 21 | sub _cmp_cmplx { |
| 22 | my ($got, $expected, $desc) = @_; |
| 23 | local $Test::Builder::Level = $Test::Builder::Level + 1; |
| 24 | |
| 25 | cmp_ok($got->[0], '==', $expected->[0], $desc); |
| 26 | cmp_ok($got->[1], '==', $expected->[1], $desc); |
| 27 | } |
| 28 | |
| 29 | SKIP: { |
| 30 | if (! defined &POSIX::2008::cabs) { skip 'cabs() UNAVAILABLE', 1; } |
| 31 | cmp_ok(POSIX::2008::cabs(3.0, 4.0), '==', 5.0, 'cabs(3, 4) == 5'); |
| 32 | } |
| 33 | |
| 34 | SKIP: { |
| 35 | if (! defined &POSIX::2008::carg) { skip 'carg() UNAVAILABLE', 2; } |
| 36 | _cmp_between(0.927295, POSIX::2008::carg(3.0, 4.0), 0.927296, 'carg(3, 4)'); |
| 37 | } |
| 38 | |
| 39 | SKIP: { |
| 40 | if (! defined &POSIX::2008::cimag) { skip 'cimag() UNAVAILABLE', 1; } |
| 41 | cmp_ok(POSIX::2008::cimag(3.0, 4.0), '==', 4.0, 'cimag(3, 4) == 4'); |
| 42 | } |
| 43 | |
| 44 | SKIP: { |
| 45 | if (! defined &POSIX::2008::cproj) { skip 'cproj() UNAVAILABLE', 2; } |
| 46 | if (my $glibcv = $Config{gnulibc_version}) { |
| 47 | my @v = split /\./, $glibcv; |
| 48 | if ($v[0] < 2 || $v[0] == 2 && $v[1] < 12) { |
| 49 | skip 'cproj() broken in glibc < 2.12', 2; |
| 50 | } |
| 51 | } |
| 52 | _cmp_cmplx([POSIX::2008::cproj(3.0, 4.0)], [3.0, 4.0], 'cproj(3, 4) == (3, 4)'); |
| 53 | } |
| 54 | |
| 55 | SKIP: { |
| 56 | if (! defined &POSIX::2008::creal) { skip 'creal() UNAVAILABLE', 1; } |
| 57 | cmp_ok(POSIX::2008::creal(3.0, 4.0), '==', 3.0, 'creal(3, 4) == 3'); |
| 58 | } |
| 59 | |
| 60 | SKIP: { |
| 61 | if (! defined &POSIX::2008::cexp) { skip 'cexp() UNAVAILABLE', 2; } |
| 62 | _cmp_cmplx([POSIX::2008::cexp(0.0, 0.0)], [1.0, 0.0], 'cexp(0, 0) == (1, 0)'); |
| 63 | } |
| 64 | |
| 65 | SKIP: { |
| 66 | if (! defined &POSIX::2008::clog) { skip 'clog() UNAVAILABLE', 2; } |
| 67 | _cmp_cmplx([POSIX::2008::clog(1.0, 0.0)], [0.0, 0.0], 'clog(1, 0) == (0, 0)'); |
| 68 | } |
| 69 | |
| 70 | SKIP: { |
| 71 | if (! defined &POSIX::2008::conj) { skip 'conj() UNAVAILABLE', 2; } |
| 72 | _cmp_cmplx([POSIX::2008::conj(3.0, 4.0)], [3.0, -4.0], 'conj(3, 4) == (3, -4)'); |
| 73 | } |
| 74 | |
| 75 | SKIP: { |
| 76 | if (! defined &POSIX::2008::cpow) { skip 'cpow() UNAVAILABLE', 2; } |
| 77 | _cmp_cmplx([POSIX::2008::cpow(1.0, 2.0, 0.0, 0.0)], [1.0, 0.0], 'cpow(1, 2, 0, 0) == (1, 0)'); |
| 78 | } |
| 79 | |
| 80 | SKIP: { |
| 81 | if (! defined &POSIX::2008::csqrt) { skip 'csqrt() UNAVAILABLE', 4; } |
| 82 | _cmp_cmplx([POSIX::2008::csqrt(9.0, 0.0)], [3.0, 0.0], 'csqrt(9, 0) == (3, 0)'); |
| 83 | _cmp_cmplx([POSIX::2008::csqrt(-9.0, 0.0)], [0.0, 3.0], 'csqrt(-9, 0) == (0, 3)'); |
| 84 | } |
| 85 | |
| 86 | SKIP: { |
| 87 | if (! defined &POSIX::2008::cacos) { skip 'cacos() UNAVAILABLE', 2; } |
| 88 | _cmp_cmplx([POSIX::2008::cacos(1.0, 0.0)], [0.0, 0.0], 'cacos(1, 0) == (0, 0)'); |
| 89 | } |
| 90 | |
| 91 | SKIP: { |
| 92 | if (! defined &POSIX::2008::cacosh) { skip 'cacosh() UNAVAILABLE', 2; } |
| 93 | _cmp_cmplx([POSIX::2008::cacosh(1.0, 0.0)], [0.0, 0.0], 'cacosh(1, 0) == (0, 0)'); |
| 94 | } |
| 95 | |
| 96 | SKIP: { |
| 97 | if (! defined &POSIX::2008::casin) { skip 'casin() UNAVAILABLE', 2; } |
| 98 | _cmp_cmplx([POSIX::2008::casin(0.0, 0.0)], [0.0, 0.0], 'casin(0, 0) == (0, 0)'); |
| 99 | } |
| 100 | |
| 101 | SKIP: { |
| 102 | if (! defined &POSIX::2008::casinh) { skip 'casinh() UNAVAILABLE', 2; } |
| 103 | _cmp_cmplx([POSIX::2008::casinh(0.0, 0.0)], [0.0, 0.0], 'casinh(0, 0) == (0, 0)'); |
| 104 | } |
| 105 | |
| 106 | SKIP: { |
| 107 | if (! defined &POSIX::2008::catan) { skip 'catan() UNAVAILABLE', 2; } |
| 108 | _cmp_cmplx([POSIX::2008::catan(0.0, 0.0)], [0.0, 0.0], 'catan(0, 0) == (0, 0)'); |
| 109 | } |
| 110 | |
| 111 | SKIP: { |
| 112 | if (! defined &POSIX::2008::catanh) { skip 'catanh() UNAVAILABLE', 2; } |
| 113 | _cmp_cmplx([POSIX::2008::catanh(0.0, 0.0)], [0.0, 0.0], 'catanh(0, 0) == (0, 0)'); |
| 114 | } |
| 115 | |
| 116 | SKIP: { |
| 117 | if (! defined &POSIX::2008::ccos) { skip 'ccos() UNAVAILABLE', 2; } |
| 118 | _cmp_cmplx([POSIX::2008::ccos(0.0, 0.0)], [1.0, 0.0], 'ccos(0, 0) == (1, 0)'); |
| 119 | } |
| 120 | |
| 121 | SKIP: { |
| 122 | if (! defined &POSIX::2008::ccosh) { skip 'ccosh() UNAVAILABLE', 2; } |
| 123 | _cmp_cmplx([POSIX::2008::ccosh(0.0, 0.0)], [1.0, 0.0], 'ccosh(0, 0) == (1, 0)'); |
| 124 | } |
| 125 | |
| 126 | SKIP: { |
| 127 | if (! defined &POSIX::2008::csin) { skip 'csin() UNAVAILABLE', 2; } |
| 128 | _cmp_cmplx([POSIX::2008::csin(0.0, 0.0)], [0.0, 0.0], 'csin(0, 0) == (0, 0)'); |
| 129 | } |
| 130 | |
| 131 | SKIP: { |
| 132 | if (! defined &POSIX::2008::csinh) { skip 'csinh() UNAVAILABLE', 2; } |
| 133 | _cmp_cmplx([POSIX::2008::csinh(0.0, 0.0)], [0.0, 0.0], 'csinh(0, 0) == (0, 0)'); |
| 134 | } |
| 135 | |
| 136 | SKIP: { |
| 137 | if (! defined &POSIX::2008::ctan) { skip 'ctan() UNAVAILABLE', 2; } |
| 138 | _cmp_cmplx([POSIX::2008::ctan(0.0, 0.0)], [0.0, 0.0], 'ctan(0, 0) == (0, 0)'); |
| 139 | } |
| 140 | |
| 141 | SKIP: { |
| 142 | if (! defined &POSIX::2008::ctanh) { skip 'ctanh() UNAVAILABLE', 2; } |
| 143 | _cmp_cmplx([POSIX::2008::ctanh(0.0, 0.0)], [0.0, 0.0], 'ctanh(0, 0) == (0, 0)'); |
| 144 | } |