Skip to content

Commit

Permalink
std/fmt: Use lowercase k for kilo in base 1000 (#1090)
Browse files Browse the repository at this point in the history
  • Loading branch information
marleck55 authored and andrewrk committed Jun 9, 2018
1 parent 670a0a3 commit 7a96355
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions std/fmt/index.zig
Expand Up @@ -559,14 +559,19 @@ pub fn formatBytes(
return output(context, "0B");
}

const mags = " KMGTPEZY";
const mags_si = " kMGTPEZY";
const mags_iec = " KMGTPEZY";
const magnitude = switch (radix) {
1000 => math.min(math.log2(value) / comptime math.log2(1000), mags.len - 1),
1024 => math.min(math.log2(value) / 10, mags.len - 1),
1000 => math.min(math.log2(value) / comptime math.log2(1000), mags_si.len - 1),
1024 => math.min(math.log2(value) / 10, mags_iec.len - 1),
else => unreachable,
};
const new_value = f64(value) / math.pow(f64, f64(radix), f64(magnitude));
const suffix = mags[magnitude];
const suffix = switch (radix) {
1000 => mags_si[magnitude],
1024 => mags_iec[magnitude],
else => unreachable,
};

try formatFloatDecimal(new_value, width, context, Errors, output);

Expand Down

0 comments on commit 7a96355

Please sign in to comment.