Skip to content

Commit 32fc550

Browse files
committed
Make an unit test of std.math IEEE 754-2008 compliant.
IEEE 754-2008 does not specify the sign bit of a NaN. The exceptions to this rule are the operations copy, negate, abs and copySign. In all other cases, the standard does not specify the sign bit (chapter 6.3 on page 35). The unit test I like to change with this pull request assumes that the sign bit of a NaN is propagated through the exp() computation. This assumption violates IEEE 754-2008. My fix is the use of abs() on the result, because this operation changes the sign bit of a NaN in a compliant way. There might be other places which must be fixed but this one really hurts me.
1 parent 9ef54a0 commit 32fc550

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

std/math.d

+2-2
Original file line numberDiff line numberDiff line change
@@ -1636,13 +1636,13 @@ unittest
16361636
resetIeeeFlags();
16371637
x = exp(real.nan);
16381638
f = ieeeFlags;
1639-
assert(isIdentical(x,real.nan));
1639+
assert(isIdentical(abs(x), real.nan));
16401640
assert(f.flags == 0);
16411641

16421642
resetIeeeFlags();
16431643
x = exp(-real.nan);
16441644
f = ieeeFlags;
1645-
assert(isIdentical(x, -real.nan));
1645+
assert(isIdentical(abs(x), real.nan));
16461646
assert(f.flags == 0);
16471647

16481648
x = exp(NaN(0x123));

0 commit comments

Comments
 (0)