Working on FP arithmetic.
authorTim Vaughan <tgvaughan@gmail.com>
Sat, 30 Jul 2016 11:55:57 +0000 (23:55 +1200)
committerTim Vaughan <tgvaughan@gmail.com>
Sat, 30 Jul 2016 11:55:57 +0000 (23:55 +1200)
float.4th [new file with mode: 0644]
scheme.4th

diff --git a/float.4th b/float.4th
new file mode 100644 (file)
index 0000000..4b73823
--- /dev/null
+++ b/float.4th
@@ -0,0 +1,26 @@
+\ Floating point arithmetic
+
+: lshift 2* ;
+: rshift 2/ ;
+
+: nlshift 0 do lshift loop ;
+: nrshift 0 do rshift loop ;
+
+1 52 nlshift 1- constant frac-mask
+1 11 nlshift 1- 52 nlshift constant exp-mask
+
+: fraction
+    frac-mask and ;
+
+: exponent
+    exp-mask and 52 nrshift ;
+
+: sign ( float -- sign  )
+    0> ;
+
+: make-float ( sign exponent fraction -- float )
+    swap 52 nlshift or
+    swap false = if
+        negate
+    then
+;
index d93e722..e1126ff 100644 (file)
@@ -11,15 +11,23 @@ defer print
 
 \ ------ Types ------
 
-0 constant fixnum-type
-1 constant boolean-type
-2 constant character-type
-3 constant string-type
-4 constant nil-type
-5 constant pair-type
-6 constant symbol-type
-7 constant primitive-proc-type
-8 constant compound-proc-type
+variable nexttype
+0 nexttype !
+: make-type
+    create nexttype @ ,
+    nexttype @ 1+ nexttype !
+    does> @ ;
+
+make-type fixnum-type
+make-type real-type
+make-type boolean-type
+make-type character-type
+make-type string-type
+make-type nil-type
+make-type pair-type
+make-type symbol-type
+make-type primitive-proc-type
+make-type compound-proc-type
 : istype? ( obj type -- obj bool )
     over = ;