diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index fad2548c8..ab57209c3 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -1049,8 +1049,8 @@ _fmt_int_128 :: proc(fi: ^Info, u: u128, base: int, is_signed: bool, bit_size: i _pad(fi, s) } // Units of measurements: -__MEMORY_LOWER := " b kb mb gb tb pb eb" -__MEMORY_UPPER := " B KB MB GB TB PB EB" +__MEMORY_LOWER := " b kib mib gib tib pib eib" +__MEMORY_UPPER := " B KiB MiB GiB TiB PiB EiB" // Formats an integer value as bytes with the best representation. // // Inputs: @@ -1069,13 +1069,13 @@ _fmt_memory :: proc(fi: ^Info, u: u64, is_signed: bool, bit_size: int, units: st div, off, unit_len := 1, 0, 1 for n := abs; n >= mem.Kilobyte; n /= mem.Kilobyte { div *= mem.Kilobyte - off += 3 + off += 4 // First iteration is slightly different because you go from // units of length 1 to units of length 2. if unit_len == 1 { off = 2 - unit_len = 2 + unit_len = 3 } } diff --git a/tests/core/fmt/test_core_fmt.odin b/tests/core/fmt/test_core_fmt.odin index 8928338b3..4459af609 100644 --- a/tests/core/fmt/test_core_fmt.odin +++ b/tests/core/fmt/test_core_fmt.odin @@ -42,18 +42,18 @@ test_fmt_memory :: proc(t: ^testing.T) { expect(t, got == exp, fmt.tprintf("(%q, %v): %q != %q", format, args, got, exp), loc) } - check(t, "5b", "%m", 5) - check(t, "5B", "%M", 5) - check(t, "-5B", "%M", -5) - check(t, "3.00kb", "%m", mem.Kilobyte * 3) - check(t, "3kb", "%.0m", mem.Kilobyte * 3) - check(t, "3KB", "%.0M", mem.Kilobyte * 3) - check(t, "3.000 mb", "%#.3m", mem.Megabyte * 3) - check(t, "3.50 gb", "%#m", u32(mem.Gigabyte * 3.5)) - check(t, "001tb", "%5.0m", mem.Terabyte) - check(t, "-01tb", "%5.0m", -mem.Terabyte) - check(t, "2.50 pb", "%#5.m", uint(mem.Petabyte * 2.5)) - check(t, "1.00 EB", "%#M", mem.Exabyte) - check(t, "255 B", "%#M", u8(255)) - check(t, "0b", "%m", u8(0)) + check(t, "5b", "%m", 5) + check(t, "5B", "%M", 5) + check(t, "-5B", "%M", -5) + check(t, "3.00kib", "%m", mem.Kilobyte * 3) + check(t, "3kib", "%.0m", mem.Kilobyte * 3) + check(t, "3KiB", "%.0M", mem.Kilobyte * 3) + check(t, "3.000 mib", "%#.3m", mem.Megabyte * 3) + check(t, "3.50 gib", "%#m", u32(mem.Gigabyte * 3.5)) + check(t, "01tib", "%5.0m", mem.Terabyte) + check(t, "-1tib", "%5.0m", -mem.Terabyte) + check(t, "2.50 pib", "%#5.m", uint(mem.Petabyte * 2.5)) + check(t, "1.00 EiB", "%#M", mem.Exabyte) + check(t, "255 B", "%#M", u8(255)) + check(t, "0b", "%m", u8(0)) }