From 06e8259c96d3282d8904006aa9137ed563d8fe86 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Mon, 14 Nov 2016 14:32:46 +1300 Subject: [PATCH] Added draft readflonum. --- src/float.4th | 15 +++++++++++++++ src/scheme.4th | 22 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/float.4th b/src/float.4th index bdedd92..c256da9 100644 --- a/src/float.4th +++ b/src/float.4th @@ -79,3 +79,18 @@ END-CODE CODE i->f pushPS(reinterpret(Int64, Float64(popPS()))) END-CODE + +: f.scientific ( float -- ) +; + +: f.plain ( float -- ) + +; + +: f. ( float -- ) + dup dup 1000000 i->f f>= swap 1 i->f 10000 i->f f/ f< or if + f.scientific + else + f.plain + then +; diff --git a/src/scheme.4th b/src/scheme.4th index c1d42e8..c448b02 100644 --- a/src/scheme.4th +++ b/src/scheme.4th @@ -853,7 +853,7 @@ parse-idx-stack parse-idx-sp ! : string? ( -- bool ) nextchar [char] " = ; -: readfixnum ( -- num-atom ) +: readfixnum ( -- fixnum ) plus? minus? or if minus? inc-parse-idx @@ -873,6 +873,26 @@ parse-idx-stack parse-idx-sp ! fixnum-type ; +: readflonum ( -- flonum ) + \ DRAFT!!! + readfixnum drop i->f + + [char] . netchar = if + 10 i->f + begin digit? while + nextchar [char] 0 - i->f over f/ f+ + inc-parse-idx + repeat + then + + [char] e nextchar = [char] E nextchar = or if + readfixnum drop i->f + f^ + then + + flonum-type +; + : readbool ( -- bool-obj ) inc-parse-idx -- 2.20.1