From: Brendan Hansen Date: Fri, 22 Jan 2021 04:29:42 +0000 (-0600) Subject: better floating point printing X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=1d3f7e1e51895e746e819dbf12b54bc05a8c3d5b;p=onyx.git better floating point printing --- diff --git a/core/alloc/logging.onyx b/core/alloc/logging.onyx index 6b49c201..30d409b5 100644 --- a/core/alloc/logging.onyx +++ b/core/alloc/logging.onyx @@ -2,8 +2,8 @@ package core.alloc.log Allocation_Action_Strings := str.[ " alloc", - "resize", " free", + "resize", ]; #private_file diff --git a/core/conv.onyx b/core/conv.onyx index 121be4fd..b596de76 100644 --- a/core/conv.onyx +++ b/core/conv.onyx @@ -1,6 +1,6 @@ package core.conv -i64_to_str :: proc (n: i64, base: u64, buf: [] u8) -> str { +i64_to_str :: proc (n: i64, base: u64, buf: [] u8, min_length := 0) -> str { is_neg := false; if n < 0 && base == 10 { is_neg = true; @@ -28,6 +28,14 @@ i64_to_str :: proc (n: i64, base: u64, buf: [] u8) -> str { c -= 1; } + if min_length > 0 && len < min_length { + for i: min_length - len { + *c = #char "0"; + len += 1; + c -= 1; + } + } + if base == 16 { *c = #char "x"; len += 1; @@ -68,7 +76,7 @@ f64_to_str :: proc (f: f64, buf: [] u8) -> str { len = s1.count + 1; if v < ~~0 do v = -v; - s2 := i64_to_str(v % 10000, 10, buf); + s2 := i64_to_str(v % 10000, 10, buf, min_length = 4); for i: 0 .. s2.count do buf.data[s1.count + 1 + i] = s2.data[i]; len += s2.count;