about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--412print-float-decimal.mu19
-rw-r--r--apps/tile/main.mu4
2 files changed, 19 insertions, 4 deletions
diff --git a/412print-float-decimal.mu b/412print-float-decimal.mu
index 00514f21..afd73d45 100644
--- a/412print-float-decimal.mu
+++ b/412print-float-decimal.mu
@@ -595,18 +595,29 @@ fn float-size in: float, precision: int -> _/eax: int {
     return 8  # hacky for scientific notation
   }
 
-  var result/eax: int <- copy n
+  # result = min(n, dp+3)
+  var result/ecx: int <- copy dp
+  result <- add 3
+  {
+    compare result, n
+    break-if-<=
+    result <- copy n
+  }
+
+  # account for decimal point
+  compare dp, n
   {
-    compare result, dp
     break-if->=
-    result <- copy dp
+    result <- increment
   }
+
+  # account for sign
   var sign/edx: int <- reinterpret in
   sign <- shift-right 0x1f
   {
     compare sign, 1
     break-if-!=
-    result <- increment  # for "-"
+    result <- increment
   }
   return result
 }
diff --git a/apps/tile/main.mu b/apps/tile/main.mu
index d81588ce..94e7b1e6 100644
--- a/apps/tile/main.mu
+++ b/apps/tile/main.mu
@@ -133,6 +133,10 @@ fn repl {
       var result/xmm0: float <- pop-number-from-value-stack stack
       print-float-decimal-approximate 0, result, 3
       print-string 0, "\n"
+      print-string 0, "width: "
+      var width/eax: int <- float-size result, 3
+      print-int32-decimal 0, width
+      print-string 0, "\n"
     }
     #
     loop