Sujet : Re: (FG.) FG.R (was Re: Bring your Forth to work)
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forthDate : 09. Mar 2025, 09:34:23
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <6fbda618fbdb67ce0828f02b0cecdb4798942511@i2pn2.org>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 9/03/2025 5:02 am, Hans Bezemer wrote:
On 08-03-2025 02:57, dxf wrote:
Ed, as usual - thank you!
Of course, I had to iron out the /STRING and BOOL tricks - but I managed. ;-)
BTW, I call ( a n -- a+1 n-1) CHOP and ( a n -- a n-1) CLIP. They're dear and well respected friends of mine. I rarely use /STRING myself.
>
One more without the temps to show anyone can write forth.
(Just don't ask me to explain it :)
\ Convert real number r to string with n digits of precision.
\ Use fixed-point if exponent -1 to n or scientific otherwise.
: (FG.) ( r n -- c-addr u )
dup >r 1- (fs.) 2dup [char] . scan ?dup if ( not nan/inf)
over swap [char] E scan over swap cskip
/number 2nip d>s dup -1 r@ within if ( fixed-point)
>r [char] . rot dup r@ 0< 2* 1+ + over r@ abs move
r> + c! nip over - r> drop exit
then 2drop
then r> 2drop ;