Skip to content

Commit ed02825

Browse files
committed
Rename BigInt.dividedBy and BigInt.toPowerOf to make the method names consistent with the other numeric types.
1 parent 314a95e commit ed02825

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

Sources/NumberKit/BigInt.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public struct BigInt: Hashable,
156156
self.init(words: [BigInt.loword(absvalue), BigInt.hiword(absvalue)], negative: value < 0.0)
157157
} else {
158158
let x = BigInt(UInt64(value.significand * pow(2.0, 63.0)))
159-
let y = x * BigInt(2).toPowerOf(BigInt(value.exponent - 63))
159+
let y = x * BigInt(2).toPower(of: BigInt(value.exponent - 63))
160160
self.init(words: y.words, negative: value < 0.0)
161161
}
162162
}
@@ -525,8 +525,13 @@ public struct BigInt: Hashable,
525525
return true
526526
}
527527

528-
/// Divides `self` by `rhs` and returns the result as a `BigInt`.
528+
@available(*, deprecated, renamed: "divided(by:)")
529529
public func dividedBy(_ rhs: BigInt) -> (quotient: BigInt, remainder: BigInt) {
530+
return self.divided(by: rhs)
531+
}
532+
533+
/// Divides `self` by `rhs` and returns the result as a `BigInt`.
534+
public func divided(by rhs: BigInt) -> (quotient: BigInt, remainder: BigInt) {
530535
guard rhs.words.count <= self.words.count else {
531536
return (BigInt(0), self.abs)
532537
}
@@ -566,8 +571,13 @@ public struct BigInt: Hashable,
566571
return (BigInt(words: res, negative: neg), BigInt(words: rem, negative: self.negative))
567572
}
568573

569-
/// Raises this `BigInt` value to the radixPow of `exp`.
574+
@available(*, deprecated, renamed: "toPower(of:)")
570575
public func toPowerOf(_ exp: BigInt) -> BigInt {
576+
return self.toPower(of: exp)
577+
}
578+
579+
/// Raises this `BigInt` value to the radixPow of `exp`.
580+
public func toPower(of exp: BigInt) -> BigInt {
571581
return pow(self, exp)
572582
}
573583

@@ -720,12 +730,12 @@ extension BigInt: ExpressibleByIntegerLiteral,
720730
}
721731

722732
public static func divideWithOverflow(_ lhs: BigInt, _ rhs: BigInt) -> (BigInt, overflow: Bool) {
723-
let res = lhs.dividedBy(rhs)
733+
let res = lhs.divided(by: rhs)
724734
return (res.quotient, overflow: false)
725735
}
726736

727737
public static func remainderWithOverflow(_ lhs: BigInt, _ rhs: BigInt) -> (BigInt, overflow: Bool) {
728-
let res = lhs.dividedBy(rhs)
738+
let res = lhs.divided(by: rhs)
729739
return (res.remainder, overflow: false)
730740
}
731741

Tests/NumberKitTests/BigIntTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ class BigIntTests: XCTestCase {
7373
func testDividedBy() {
7474
let x1: BigInt = "38274945700000001034304000022452452525224002449"
7575
let x2: BigInt = "1234567890123456789"
76-
let r1 = x1.dividedBy(x2)
76+
let r1 = x1.divided(by: x2)
7777
XCTAssert(r1.quotient == "31002706296024357530217920519")
7878
XCTAssert(r1.remainder == "654242677691048958")
7979
let x3: BigInt = "3827494570900000103430410002245245252522400244999"
8080
let x4: BigInt = "12345678901234567892344542545242452245"
81-
let r2 = x3.dividedBy(x4)
81+
let r2 = x3.divided(by: x4)
8282
XCTAssert(r2.quotient == "310027063033")
8383
XCTAssert(r2.remainder == "1772541951990552417813256094292885914")
8484
XCTAssert((x3 / x3) == BigInt(1))
@@ -97,7 +97,7 @@ class BigIntTests: XCTestCase {
9797
func testPowerOf() {
9898
let x1: BigInt = "84570248572048572408572048572048"
9999
let y1 = x1 * x1 * x1 * x1
100-
XCTAssert(x1.toPowerOf(BigInt(4)) == y1)
100+
XCTAssert(x1.toPower(of: BigInt(4)) == y1)
101101
}
102102

103103
func testDoubleConversion() {

0 commit comments

Comments
 (0)