From e8fdb1e66ea6d3790e7b7d7b44676418c0081626 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Wed, 27 Apr 2016 12:25:53 +1200 Subject: [PATCH] Fixed */ def, added fixed point arithmetic to example. --- examples/mandelbrot.4th | 31 +++++++++++++++++++++++-------- src/lib.4th | 2 +- 2 files changed, 24 insertions(+), 9 deletions(-) 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 - ; -- 2.20.1