Skip to content

Commit 8f819ff

Browse files
committed
[NFC] Add some comments and make two internal methods @inlinable
1 parent 87b62a9 commit 8f819ff

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/BigIntModule/BigInt._Significand.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ extension BigInt._Significand {
581581
return overflow
582582
}
583583

584-
// @inlinable
584+
@inlinable
585585
internal mutating func multiply(by other: UInt) {
586586
var carry = 0 as UInt
587587
for i in 0..<count {
@@ -621,6 +621,10 @@ extension BigInt._Significand {
621621
}
622622

623623
func multiply(_ lhs: Slice<Self>, _ rhs: Slice<Self>) -> Self {
624+
625+
// Based on Karatsuba's method. For details see:
626+
// <https://mathworld.wolfram.com/KaratsubaMultiplication.html>.
627+
624628
let m = (Swift.max(lhs.count, rhs.count) + 1) / 2
625629
guard m >= karatsubaThreshold else {
626630
if lhs.isEmpty || rhs.isEmpty { return Self() }
@@ -648,7 +652,7 @@ extension BigInt._Significand {
648652
return multiply(self[...], other[...])
649653
}
650654

651-
// @inlinable
655+
@inlinable
652656
@discardableResult
653657
internal mutating func divide(by other: UInt) -> /* remainder: */ Self {
654658
if other == 1 { return Self() }
@@ -688,8 +692,8 @@ extension BigInt._Significand {
688692
}
689693
}
690694

691-
// Based on Knuth's Algorithm D.
692-
// For details see <https://skanthak.homepage.t-online.de/division.html>.
695+
// Based on Knuth's Algorithm D (section 4.3.1). For details see:
696+
// <https://skanthak.homepage.t-online.de/division.html>.
693697

694698
// We'll remove any extraneous leading zero words while determining by how
695699
// much to shift our operands.

0 commit comments

Comments
 (0)