Skip to content

Commit b963f7c

Browse files
committed
[stdlib] Int128: Fix thinko in _wideDivide22
1 parent b7cae85 commit b963f7c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

stdlib/public/core/Int128.swift.gyb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,9 @@ private func _wideDivide22<F: FixedWidthInteger & UnsignedInteger>(
725725

726726
// Left shift both rhs and lhs, then divide and right shift the remainder.
727727
let shift = F.Magnitude(rhs.high.leadingZeroBitCount)
728+
let rollover = F.Magnitude(F.bitWidth + F.Magnitude.bitWidth) &- shift
728729
let rhs = _wideMaskedShiftLeft(rhs, shift)
729-
let high = _wideMaskedShiftRight(lhs, F.Magnitude(F.bitWidth) &- shift).low
730+
let high = _wideMaskedShiftRight(lhs, rollover).low
730731
let lhs = _wideMaskedShiftLeft(lhs, shift)
731732
let (quotient, remainder) = _wideDivide32(
732733
(F(high), F.Magnitude(lhs.high), lhs.low), by: rhs)

0 commit comments

Comments
 (0)