Skip to content

Commit

Permalink
[NBKCoreKit] StrictUnsignedInteger (#83).
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Sep 20, 2023
1 parent b125678 commit ac40ed1
Show file tree
Hide file tree
Showing 16 changed files with 1,154 additions and 692 deletions.
13 changes: 11 additions & 2 deletions Sources/NBKCoreKit/Private/NBK+Division.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,18 @@ extension NBK {
return PVO(dividend._lowWord & (divisor &- 1), false)
}
//=--------------------------------------=
if divisor.isZero {
return PVO(dividend._lowWord, true)
}
//=--------------------------------------=
let minus = T.isSigned && dividend < T.zero
let pvo = NBK.remainderReportingOverflowAsLenientUnsignedInteger(of: dividend.magnitude.words, dividingBy: divisor)
return PVO((minus && !pvo.partialValue.isZero) ? (divisor &- pvo.partialValue) : pvo.partialValue, pvo.overflow)
var remainder = 000000000000000000 as UInt

for word in dividend.magnitude.words.reversed() {
remainder = divisor.dividingFullWidth(HL(high: remainder, low: word)).remainder
}

return PVO((minus && !remainder.isZero) ? (divisor &- remainder) : remainder, false)
}

/// Returns the least positive `residue` of dividing the `dividend` by `source.bitWidth`.
Expand Down
256 changes: 0 additions & 256 deletions Sources/NBKCoreKit/Private/NBK+Limbs+Addition.swift

This file was deleted.

37 changes: 0 additions & 37 deletions Sources/NBKCoreKit/Private/NBK+Limbs+Multiplication.swift

This file was deleted.

Loading

0 comments on commit ac40ed1

Please sign in to comment.