mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 20:58:15 +00:00
use KiB etc. instead of KB
This commit is contained in:
+4
-4
@@ -1049,8 +1049,8 @@ _fmt_int_128 :: proc(fi: ^Info, u: u128, base: int, is_signed: bool, bit_size: i
|
|||||||
_pad(fi, s)
|
_pad(fi, s)
|
||||||
}
|
}
|
||||||
// Units of measurements:
|
// Units of measurements:
|
||||||
__MEMORY_LOWER := " b kb mb gb tb pb eb"
|
__MEMORY_LOWER := " b kib mib gib tib pib eib"
|
||||||
__MEMORY_UPPER := " B KB MB GB TB PB EB"
|
__MEMORY_UPPER := " B KiB MiB GiB TiB PiB EiB"
|
||||||
// Formats an integer value as bytes with the best representation.
|
// Formats an integer value as bytes with the best representation.
|
||||||
//
|
//
|
||||||
// Inputs:
|
// 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
|
div, off, unit_len := 1, 0, 1
|
||||||
for n := abs; n >= mem.Kilobyte; n /= mem.Kilobyte {
|
for n := abs; n >= mem.Kilobyte; n /= mem.Kilobyte {
|
||||||
div *= mem.Kilobyte
|
div *= mem.Kilobyte
|
||||||
off += 3
|
off += 4
|
||||||
|
|
||||||
// First iteration is slightly different because you go from
|
// First iteration is slightly different because you go from
|
||||||
// units of length 1 to units of length 2.
|
// units of length 1 to units of length 2.
|
||||||
if unit_len == 1 {
|
if unit_len == 1 {
|
||||||
off = 2
|
off = 2
|
||||||
unit_len = 2
|
unit_len = 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
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, "5B", "%M", 5)
|
||||||
check(t, "-5B", "%M", -5)
|
check(t, "-5B", "%M", -5)
|
||||||
check(t, "3.00kb", "%m", mem.Kilobyte * 3)
|
check(t, "3.00kib", "%m", mem.Kilobyte * 3)
|
||||||
check(t, "3kb", "%.0m", mem.Kilobyte * 3)
|
check(t, "3kib", "%.0m", mem.Kilobyte * 3)
|
||||||
check(t, "3KB", "%.0M", mem.Kilobyte * 3)
|
check(t, "3KiB", "%.0M", mem.Kilobyte * 3)
|
||||||
check(t, "3.000 mb", "%#.3m", mem.Megabyte * 3)
|
check(t, "3.000 mib", "%#.3m", mem.Megabyte * 3)
|
||||||
check(t, "3.50 gb", "%#m", u32(mem.Gigabyte * 3.5))
|
check(t, "3.50 gib", "%#m", u32(mem.Gigabyte * 3.5))
|
||||||
check(t, "001tb", "%5.0m", mem.Terabyte)
|
check(t, "01tib", "%5.0m", mem.Terabyte)
|
||||||
check(t, "-01tb", "%5.0m", -mem.Terabyte)
|
check(t, "-1tib", "%5.0m", -mem.Terabyte)
|
||||||
check(t, "2.50 pb", "%#5.m", uint(mem.Petabyte * 2.5))
|
check(t, "2.50 pib", "%#5.m", uint(mem.Petabyte * 2.5))
|
||||||
check(t, "1.00 EB", "%#M", mem.Exabyte)
|
check(t, "1.00 EiB", "%#M", mem.Exabyte)
|
||||||
check(t, "255 B", "%#M", u8(255))
|
check(t, "255 B", "%#M", u8(255))
|
||||||
check(t, "0b", "%m", u8(0))
|
check(t, "0b", "%m", u8(0))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user