Skip to content

Commit 085e312

Browse files
added string localization interpolation support for HugeInt and HugeFloat
1 parent 9b332ef commit 085e312

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Sources/huge-numbers/huge_numbers.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,26 @@
44
//
55
// Created by Evan Anderson on 4/10/23.
66
//
7+
8+
import Foundation
9+
10+
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
11+
public extension String.LocalizationValue.StringInterpolation {
12+
mutating func appendLiteral(_ value: HugeInt) {
13+
// TODO: fix (doesn't support any number larger than UInt64.max)
14+
let number:Int = value.to_int() ?? -1
15+
appendInterpolation(number)
16+
}
17+
mutating func appendInterpolation(_ value: HugeInt) {
18+
appendLiteral(value)
19+
}
20+
21+
mutating func appendLiteral(_ value: HugeFloat) {
22+
// TODO: fix (doesn't support any number larger than Double.max -> gets represented as an infinity symbol; only supports 6 decimal digits; can only be represented in base 2)
23+
let number:Float = value.represented_float
24+
appendInterpolation(number)
25+
}
26+
mutating func appendInterpolation(_ value: HugeFloat) {
27+
appendLiteral(value)
28+
}
29+
}

0 commit comments

Comments
 (0)