| ... | @@ -868,11 +868,14 @@ pub fn formatBytes( | ... | @@ -868,11 +868,14 @@ pub fn formatBytes( |
| 868 | return out_stream.writeAll("0B"); | 868 | return out_stream.writeAll("0B"); |
| 869 | } | 869 | } |
| 870 | | 870 | |
| | 871 | const is_float = comptime std.meta.trait.is(.Float)(@TypeOf(value)); |
| 871 | const mags_si = " kMGTPEZY"; | 872 | const mags_si = " kMGTPEZY"; |
| 872 | const mags_iec = " KMGTPEZY"; | 873 | const mags_iec = " KMGTPEZY"; |
| | 874 | |
| | 875 | const log2 = if (is_float) @floatToInt(usize, math.log2(value)) else math.log2(value); |
| 873 | const magnitude = switch (radix) { | 876 | const magnitude = switch (radix) { |
| 874 | 1000 => math.min(math.log2(value) / comptime math.log2(1000), mags_si.len - 1), | 877 | 1000 => math.min(log2 / comptime math.log2(1000), mags_si.len - 1), |
| 875 | 1024 => math.min(math.log2(value) / 10, mags_iec.len - 1), | 878 | 1024 => math.min(log2 / 10, mags_iec.len - 1), |
| 876 | else => unreachable, | 879 | else => unreachable, |
| 877 | }; | 880 | }; |
| 878 | const new_value = lossyCast(f64, value) / math.pow(f64, lossyCast(f64, radix), lossyCast(f64, magnitude)); | 881 | const new_value = lossyCast(f64, value) / math.pow(f64, lossyCast(f64, radix), lossyCast(f64, magnitude)); |