Skip to content

Commit 30b3763

Browse files
committed
Fix underflow in the padding calculation
1 parent 40eaaac commit 30b3763

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

benchmark/utils/DriverUtils.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -617,19 +617,23 @@ final class TestRunner {
617617
}
618618
}
619619
func printToWidth(_ s: String, width: Int, justify: Justification = .left) {
620-
let pad = width - 1 - s.count
620+
var pad = width - 1 - s.count
621+
if pad <= 0 {
622+
pad = 1
623+
}
621624
if justify == .right {
622625
printSpaces(pad)
623626
}
624-
print(s, terminator: " ")
627+
print(s)
625628
if justify == .left {
626629
printSpaces(pad)
627630
}
628631
}
629632
func printDoubleToWidth(_ d: Double, fractionDigits: Int = 3, width: Int) {
630633
let digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
631-
// 10 ** fractionDigits -- This suffices for up to 8 digits
632-
let scale = (0..<fractionDigits).reduce(1, {i,_ in i * 10})
634+
// Handle up to 8 fraction digits
635+
let scales = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000]
636+
let scale = scales[fractionDigits]
633637
let i = Int(d * Double(scale) + 0.5)
634638
let intPart = i / scale
635639
let fraction = i % scale

0 commit comments

Comments
 (0)