Skip to content

Commit 88a042c

Browse files
committed
Fix Float/Double .nextUp/.nextDown on arm(v7).
On armv7, leastNonzeroMagnitude is defined to be leastNormalMagnitude. This seems wrong to me from a language point of view, because it's possible to have a nonzero float that compares less than the leastNonzero float. However, it must have been done to gloss over hardware rounding errors. This is not a problem on arm64. As a result, nextUp/Down methods were not self-consistent. I fixed this by skipping over subnormal representations, following the precedent set by leastNonZeroMagnitude. This fixes the FloatingPoint floatNextUpDownTests on armv7.
1 parent 07d0a62 commit 88a042c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,13 @@ extension ${Self}: BinaryFloatingPoint {
484484
exponentBitPattern: exponentBitPattern + 1,
485485
significandBitPattern: 0)
486486
}
487+
#if arch(arm)
488+
// On arm, subnormals are skipped.
489+
if exponentBitPattern == 0 {
490+
_sanityCheck(self < .leastNonzeroMagnitude, "subnormal out of range")
491+
return .leastNonzeroMagnitude
492+
}
493+
#endif
487494
return ${Self}(sign: .plus,
488495
exponentBitPattern: exponentBitPattern,
489496
significandBitPattern: significandBitPattern + 1)

0 commit comments

Comments
 (0)