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 Perl#21533
  • Loading branch information
tonycoz committed Nov 2, 2023
1 parent 20793c3 commit 6464ba2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/POSIX/t/math.t
Original file line number Diff line number Diff line change
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 6464ba2

Please sign in to comment.