mirror of
https://github.com/apple/swift-numerics
synced 2026-11-26 04:57:53 +00:00
[BigInt] Move the CustomStringConvertible conformance
This commit is contained in:
1 parent
368caf5b3f
commit
2419741a7c
1 file changed
+20
-17
+20
-17
@@ -79,6 +79,26 @@ extension BigInt: Comparable {
|
||||
}
|
||||
}
|
||||
|
||||
extension BigInt: CustomStringConvertible {
|
||||
|
||||
public var description: String {
|
||||
var result = ""
|
||||
|
||||
if words.count == 1 {
|
||||
return Int64(bitPattern: UInt64(words[0])).description
|
||||
} else {
|
||||
var next = abs(self)
|
||||
while next != 0 {
|
||||
let digit: BigInt
|
||||
(next, digit) = BigInt._div(lhs: next, rhs: 10)
|
||||
result += "\(digit.words[0])"
|
||||
}
|
||||
}
|
||||
|
||||
return (self < 0 ? "-" : "") + String(result.reversed())
|
||||
}
|
||||
}
|
||||
|
||||
extension BigInt {
|
||||
|
||||
public init?(_ description: String) {
|
||||
@@ -722,23 +742,6 @@ extension BigInt {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
var result = ""
|
||||
|
||||
if words.count == 1 {
|
||||
return Int64(bitPattern: UInt64(words[0])).description
|
||||
} else {
|
||||
var next = abs(self)
|
||||
while next != 0 {
|
||||
let digit: BigInt
|
||||
(next, digit) = BigInt._div(lhs: next, rhs: 10)
|
||||
result += "\(digit.words[0])"
|
||||
}
|
||||
}
|
||||
|
||||
return (self < 0 ? "-" : "") + String(result.reversed())
|
||||
}
|
||||
}
|
||||
|
||||
// inspired by https://eli.thegreenplace.net/2009/03/21/efficient-integer-exponentiation-algorithms
|
||||
|
||||
Reference in new issue
Block a user