better floating point printing
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 22 Jan 2021 04:29:42 +0000 (22:29 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 22 Jan 2021 04:29:42 +0000 (22:29 -0600)
core/alloc/logging.onyx
core/conv.onyx

index 6b49c201e8f0caa0009066867537f5847aa82583..30d409b5985bcd50ed71245f9ea4cb2b7d8a989c 100644 (file)
@@ -2,8 +2,8 @@ package core.alloc.log
 
 Allocation_Action_Strings := str.[
     " alloc",
-    "resize",
     "  free",
+    "resize",
 ];
 
 #private_file
index 121be4fd24663daaace81c78d54bb2db75ff033d..b596de76c1fcf332ae8ba487350dbe60eabbe27d 100644 (file)
@@ -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;