From: Tim Vaughan Date: Mon, 14 Nov 2016 01:32:46 +0000 (+1300) Subject: Added draft readflonum. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=scheme.forth.jl.git;a=commitdiff_plain;h=06e8259c96d3282d8904006aa9137ed563d8fe86 Added draft readflonum. --- 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