Skip to content

Commit e197f15

Browse files
committed
refactor: update numeric formatting
1 parent a8624e6 commit e197f15

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ let package = Package(
3333
)
3434
],
3535
dependencies: [
36-
.package(path: "../swift-standards"),
37-
.package(path: "../swift-iso-9899")
36+
.package(url: "https://github.com/swift-standards/swift-standards.git", from: "0.1.0"),
37+
.package(url: "https://github.com/swift-standards/swift-svg-standard.git", from: "0.1.0"),
38+
.package(url: "https://github.com/swift-standards/swift-iso-9899.git", from: "0.1.0"),
3839
],
3940
targets: [
4041
.target(

Sources/Numeric Formatting/Format.Numeric.Style.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ extension Format.Numeric.Style {
185185
if ISO_9899.Math.fabs(increment - Double(Int64(increment))) > 1e-10 {
186186
var tempInc = increment
187187
var decimalPlaces = 0
188-
while ISO_9899.Math.fabs(tempInc - Double(Int64(tempInc))) > 1e-10 && decimalPlaces < 15 {
188+
while (tempInc - Double(Int64(tempInc))).c.abs > 1e-10 && decimalPlaces < 15 {
189189
tempInc *= 10
190190
decimalPlaces += 1
191191
}
@@ -212,7 +212,7 @@ extension Format.Numeric.Style {
212212
}
213213

214214
let isNegative = doubleValue < 0
215-
let absoluteValue = ISO_9899.Math.fabs(doubleValue)
215+
let absoluteValue = doubleValue.c.abs
216216

217217
// Apply minimum if specified
218218
var effectiveMinFrac = minimumFractionDigits
@@ -283,7 +283,7 @@ extension Format.Numeric.Style {
283283
let integerString = formatIntegerPart(integerPart)
284284

285285
// Handle fractional part
286-
if ISO_9899.Math.fabs(fractionalPart) < 1e-10 && effectiveMinFrac == nil {
286+
if fractionalPart.c.abs < 1e-10 && effectiveMinFrac == nil {
287287
// Whole number with no minimum fraction digits
288288
var result = integerString
289289
if case .always = decimalSeparatorStrategy {
@@ -403,7 +403,7 @@ extension Format.Numeric.Style {
403403

404404
private func formatWithNotation(_ value: Double) -> String {
405405
let isNegative = value < 0
406-
let absoluteValue = ISO_9899.Math.fabs(value)
406+
let absoluteValue = value.c.abs
407407

408408
switch notation {
409409
case .automatic:
@@ -523,7 +523,7 @@ extension Format.Numeric.Style {
523523
let intPart = Int64(rounded)
524524
let fracPart = rounded - Double(intPart)
525525

526-
if ISO_9899.Math.fabs(fracPart) < 1e-10 {
526+
if fracPart.c.abs < 1e-10 {
527527
return String(intPart)
528528
}
529529

@@ -555,7 +555,7 @@ extension Format.Numeric.Style {
555555
let intPart = Int64(rounded)
556556
let fracPart = rounded - Double(intPart)
557557

558-
if ISO_9899.Math.fabs(fracPart) < 1e-10 {
558+
if fracPart.c.abs < 1e-10 {
559559
return String(intPart)
560560
}
561561

@@ -575,7 +575,7 @@ extension Format.Numeric.Style {
575575

576576
private func formatWithSignificantDigits(_ value: Double, min: Int?, max: Int?) -> String {
577577
let isNegative = value < 0
578-
let absoluteValue = ISO_9899.Math.fabs(value)
578+
let absoluteValue = value.c.abs
579579

580580
if absoluteValue == 0 {
581581
let minDigits = min ?? 1

0 commit comments

Comments
 (0)