Skip to content

Commit

Permalink
ext/POSIX/t/math.t: don't assume the sign of NaN
Browse files Browse the repository at this point in the history
The test in Configure warns:

/* Note that whether the sign bit is on or off
 * for NaN depends on the CPU/FPU, and possibly
 * can be affected by the build toolchain.

but this test assumed that the default NaN was always positive,
but this isn't the case with the Sun/Oracle workshop cc, whether
on Oracle Linux or on Solaris.

copysign() is however well defined for NaN, so we can modify the
sign on NaN and test that with signbit().

Fixes #21533
  • Loading branch information
tonycoz committed Nov 6, 2023
1 parent 2d3e973 commit b17b9cc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/POSIX/t/math.t
Expand Up @@ -293,7 +293,8 @@ SKIP: {
like(NAN, qr/^NaN/, "NAN is Perl's NaN");
cmp_ok(NAN, '!=', NAN, "NAN != NAN");
ok(!(NAN == NAN), "NAN == NAN");
ok(!signbit(NAN), "signbit(NAN)");
ok(!signbit(copysign(NAN, 1.0)), "signbit(copysign(NAN, 1.0)))");
ok(signbit(copysign(NAN, -1.0)), "signbit(copysign(NAN, -1.0)))");
}

done_testing();

0 comments on commit b17b9cc

Please sign in to comment.