authorgravatar for 40122305+marleck55@users.noreply.github.commarleck55 <40122305+marleck55@users.noreply.github.com> 2018-06-09 18:05:58+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-09 12:05:58-04:00
log7a9635555b5ddc681134ebe0e0e9f4f373ac5025
tree8865d18be17af39f723d257a1c224b2d8afad1d0
parent670a0a3eed2e8806177e4eac3382e8b1fad4059e

std/fmt: Use lowercase k for kilo in base 1000 (#1090)


1 files changed, 9 insertions(+), 4 deletions(-)

std/fmt/index.zig+9-4
...@@ -559,14 +559,19 @@ pub fn formatBytes(...@@ -559,14 +559,19 @@ pub fn formatBytes(
559 return output(context, "0B");559 return output(context, "0B");
560 }560 }
561561
562 const mags = " KMGTPEZY";562 const mags_si = " kMGTPEZY";
563 const mags_iec = " KMGTPEZY";
563 const magnitude = switch (radix) {564 const magnitude = switch (radix) {
564 1000 => math.min(math.log2(value) / comptime math.log2(1000), mags.len - 1),565 1000 => math.min(math.log2(value) / comptime math.log2(1000), mags_si.len - 1),
565 1024 => math.min(math.log2(value) / 10, mags.len - 1),566 1024 => math.min(math.log2(value) / 10, mags_iec.len - 1),
566 else => unreachable,567 else => unreachable,
567 };568 };
568 const new_value = f64(value) / math.pow(f64, f64(radix), f64(magnitude));569 const new_value = f64(value) / math.pow(f64, f64(radix), f64(magnitude));
569 const suffix = mags[magnitude];570 const suffix = switch (radix) {
571 1000 => mags_si[magnitude],
572 1024 => mags_iec[magnitude],
573 else => unreachable,
574 };
570575
571 try formatFloatDecimal(new_value, width, context, Errors, output);576 try formatFloatDecimal(new_value, width, context, Errors, output);
572577