mirror of
https://github.com/apple/swift-numerics
synced 2026-11-30 05:28:47 +00:00
[BigInt] Move the Comparable conformance
This commit is contained in:
1 parent
a799618103
commit
368caf5b3f
1 file changed
+27
-24
+27
-24
@@ -52,6 +52,33 @@ extension BigInt: Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
extension BigInt: Comparable {
|
||||
|
||||
@inlinable
|
||||
public static func < (lhs: BigInt, rhs: BigInt) -> Bool {
|
||||
let lhsNegative = lhs._isNegative
|
||||
let rhsNegative = rhs._isNegative
|
||||
|
||||
if lhsNegative && !rhsNegative { return true }
|
||||
if rhsNegative && !lhsNegative { return false }
|
||||
|
||||
if (lhsNegative && rhsNegative) || (!lhsNegative && !rhsNegative) {
|
||||
if lhs.words.count > rhs.words.count {
|
||||
return lhsNegative ? true : false
|
||||
}
|
||||
if lhs.words.count < rhs.words.count {
|
||||
return lhsNegative ? false : true
|
||||
}
|
||||
|
||||
for i in stride(from: lhs.words.count - 1, through: 0, by: -1) {
|
||||
if lhs.words[i] > rhs.words[i] { return false }
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension BigInt {
|
||||
|
||||
public init?(_ description: String) {
|
||||
@@ -314,30 +341,6 @@ extension BigInt {
|
||||
|
||||
public var trailingZeroBitCount: Int { words.first?.trailingZeroBitCount ?? 0 }
|
||||
|
||||
@inlinable
|
||||
public static func < (lhs: BigInt, rhs: BigInt) -> Bool {
|
||||
let lhsNegative = lhs._isNegative
|
||||
let rhsNegative = rhs._isNegative
|
||||
|
||||
if lhsNegative && !rhsNegative { return true }
|
||||
if rhsNegative && !lhsNegative { return false }
|
||||
|
||||
if (lhsNegative && rhsNegative) || (!lhsNegative && !rhsNegative) {
|
||||
if lhs.words.count > rhs.words.count {
|
||||
return lhsNegative ? true : false
|
||||
}
|
||||
if lhs.words.count < rhs.words.count {
|
||||
return lhsNegative ? false : true
|
||||
}
|
||||
|
||||
for i in stride(from: lhs.words.count - 1, through: 0, by: -1) {
|
||||
if lhs.words[i] > rhs.words[i] { return false }
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public static func / (lhs: BigInt, rhs: BigInt) -> BigInt {
|
||||
let (result, _) = _div(lhs: lhs, rhs: rhs)
|
||||
|
||||
Reference in new issue
Block a user