Skip to content

Commit

Permalink
[NFC] Add some comments and make two internal methods @inlinable
Browse files Browse the repository at this point in the history
  • Loading branch information
xwu committed Jun 10, 2020
1 parent 87b62a9 commit 8f819ff
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Sources/BigIntModule/BigInt._Significand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ extension BigInt._Significand {
return overflow
}

// @inlinable
@inlinable
internal mutating func multiply(by other: UInt) {
var carry = 0 as UInt
for i in 0..<count {
Expand Down Expand Up @@ -621,6 +621,10 @@ extension BigInt._Significand {
}

func multiply(_ lhs: Slice<Self>, _ rhs: Slice<Self>) -> Self {

// Based on Karatsuba's method. For details see:
// <https://mathworld.wolfram.com/KaratsubaMultiplication.html>.

let m = (Swift.max(lhs.count, rhs.count) + 1) / 2
guard m >= karatsubaThreshold else {
if lhs.isEmpty || rhs.isEmpty { return Self() }
Expand Down Expand Up @@ -648,7 +652,7 @@ extension BigInt._Significand {
return multiply(self[...], other[...])
}

// @inlinable
@inlinable
@discardableResult
internal mutating func divide(by other: UInt) -> /* remainder: */ Self {
if other == 1 { return Self() }
Expand Down Expand Up @@ -688,8 +692,8 @@ extension BigInt._Significand {
}
}

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

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

0 comments on commit 8f819ff

Please sign in to comment.