about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-11-29 12:51:57 -0800
committerKartik Agaram <vc@akkartik.com>2020-11-29 12:51:57 -0800
commitee3ddc3961d81059863cc1ea8245306ecb381dce (patch)
treedcb247d33eb15bf02d5bed550755d3135e47de08
parent614b132b2e00178f67e3e5dee38d14b9eee806cb (diff)
downloadmu-ee3ddc3961d81059863cc1ea8245306ecb381dce.tar.gz
7302 - tile: at long last, division
Also square roots.

But there's a bug in rendering floats without precision.
-rw-r--r--apps/tile/environment.mu2
-rw-r--r--apps/tile/rpn.mu20
2 files changed, 21 insertions, 1 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 4ebd41d2..6d6b91ec 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -1517,7 +1517,7 @@ fn render-primitives screen: (addr screen), bottom-margin-row: int, right-col: i
   row <- subtract 1
   var col/edx: int <- copy 1
   move-cursor screen, row, col
-  row, col <- render-primitive-group screen, row, col, right-col, "numbers: ", "+ - *  "
+  row, col <- render-primitive-group screen, row, col, right-col, "numbers: ", "+ - * / sqrt  "
   row, col <- render-primitive-group screen, row, col, right-col, "arrays: ", "len  "
   row, col <- render-primitive-group screen, row, col, right-col, "files: ", "open read slurp lines  "
   row, col <- render-primitive-group screen, row, col, right-col, "misc: ", "dup swap  "  # hack: keep these at the right of the bottom row
diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu
index 193bd2c9..219e9b09 100644
--- a/apps/tile/rpn.mu
+++ b/apps/tile/rpn.mu
@@ -50,6 +50,26 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         push-number-to-value-stack out, a
         break $evaluate:process-word
       }
+      {
+        var is-div?/eax: boolean <- stream-data-equal? curr-stream, "/"
+        compare is-div?, 0
+        break-if-=
+        var _b/xmm0: float <- pop-number-from-value-stack out
+        var b/xmm1: float <- copy _b
+        var a/xmm0: float <- pop-number-from-value-stack out
+        a <- divide b
+        push-number-to-value-stack out, a
+        break $evaluate:process-word
+      }
+      {
+        var is-sqrt?/eax: boolean <- stream-data-equal? curr-stream, "sqrt"
+        compare is-sqrt?, 0
+        break-if-=
+        var a/xmm0: float <- pop-number-from-value-stack out
+        a <- square-root a
+        push-number-to-value-stack out, a
+        break $evaluate:process-word
+      }
       ## strings/arrays
       {
         var is-len?/eax: boolean <- stream-data-equal? curr-stream, "len"