mirror of
https://github.com/apple/swift-numerics
synced 2026-11-26 04:57:53 +00:00
[BigInt] Move the LosslessStringConvertible conformance
This commit is contained in:
1 parent
2419741a7c
commit
5db4a69e57
1 file changed
+6
-3
@@ -9,7 +9,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
public struct BigInt: SignedInteger, LosslessStringConvertible {
|
||||
public struct BigInt: SignedInteger {
|
||||
public private(set) var words: [UInt]
|
||||
|
||||
@usableFromInline
|
||||
@@ -99,12 +99,12 @@ extension BigInt: CustomStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
extension BigInt {
|
||||
extension BigInt: LosslessStringConvertible {
|
||||
|
||||
public init?(_ description: String) {
|
||||
let isNegative = description.hasPrefix("-")
|
||||
let hasPrefixOperator = isNegative || description.hasPrefix("+")
|
||||
|
||||
|
||||
let unprefixedDescription = hasPrefixOperator ? description.dropFirst() : description[...]
|
||||
guard !unprefixedDescription.isEmpty else { return nil }
|
||||
|
||||
@@ -123,6 +123,9 @@ extension BigInt {
|
||||
|
||||
words = result.words
|
||||
}
|
||||
}
|
||||
|
||||
extension BigInt {
|
||||
|
||||
public init?<T>(exactly source: T) where T: BinaryInteger {
|
||||
self.init(source)
|
||||
|
||||
Reference in new issue
Block a user