From: Tim Vaughan Date: Wed, 27 Apr 2016 00:25:53 +0000 (+1200) Subject: Fixed */ def, added fixed point arithmetic to example. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=e8fdb1e66ea6d3790e7b7d7b44676418c0081626;p=forth.jl.git Fixed */ def, added fixed point arithmetic to example. --- diff --git a/examples/mandelbrot.4th b/examples/mandelbrot.4th index 254628c..c75ebd0 100644 --- a/examples/mandelbrot.4th +++ b/examples/mandelbrot.4th @@ -1,4 +1,12 @@ -( --- Complex integer arithmetic --- ) +( --- Complex arithmetic --- ) + +( Location of floating point. ) +: precision 10000 ; + +: >scaled precision 10 / * swap precision * + ; + +( Redefine multiplication. Yay forth! ) +: * precision */ ; : c* ( x1 y1 x2 y2 -- x3 y3 ) swap -rot ( x1 x2 y1 y2 ) @@ -28,15 +36,22 @@ : inSet? ( cr ci -- res ) - 100 0 DO + 100 0 do - 2SWAP 2DUP 5 ROLL 5 ROLL + 2swap 2dup 5 roll 5 roll iterate - 2DUP cmagsq - 100 > IF - LEAVE - THEN + 2dup cmagsq + 100 > if + leave + then + + loop +; + +( Draw the Mandelbrot Set!) +: mandel ( x1 y1 x2 y2 -- ) - LOOP ; +( Clean up - hide non-standard multiplication def. ) +hide * diff --git a/src/lib.4th b/src/lib.4th index f4b28e6..efadf95 100644 --- a/src/lib.4th +++ b/src/lib.4th @@ -1,6 +1,6 @@ : / /MOD SWAP DROP ; : MOD /MOD DROP ; -: */ * / ; +: */ -ROT * SWAP / ; : NEGATE 0 SWAP - ;