🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.forth
Article #30

Re: F.N floating point format word

#30
From: Krishna Myneni
Date: Thu, 08 Oct 2026 14:18
108 lines
4959 bytes
On 10/8/26 8:26 AM, peter wrote:
> On Thu, 8 Oct 2026 12:13:02 +0200
> peter <peter.noreply@tin.it> wrote:
> 
>> On Thu, 8 Oct 2026 13:34:33 +1100
>> dxf <dxforth@gmail.com> wrote:
>>
>>> On 8/10/2026 7:35 am, peter wrote:
>>>> ...
>>>> There were no real reason. The result at fpad is used only for
>>>> INF and NAN. I also wanted a number larger then 17, 32 looked like
>>>> a good round number. The importance of the first call to represent
>>>> is to get a correct exp to use in the following calculations.
>>>> The second time represent is called it will be with u=exp+n to get
>>>> the correct rounding.
>>>
>>> Are you sure it's necessary?  Your tests appear to work with it set at 5.
>>>
>>
>> You might be right!
>> My first concern was for number like
>> 9.9999999995e that will round up all the way and get a exp+1
>> But it looks like the code handles that also.
>>
>> The problem was 99.995e 2 f.n that became 100.0
>> But that was solved also by pre-filling the buffer with 0 and always
>> printing the correct number of decimals
>>
>> BR
>> Peter
>>
> 
> Thanks to dxf's question I continued testing and found an error.
> 
> 0.999955555e 2 f.n  0.0100
> 
> What happened was that in this case exp from the first represent is 0
> in the test to choose action f.n-case-e<=0 get chosen. In this part
> exp is recalculated and became 1!
> The correction is to move the second represent earlier before choosing.
> 
> the relevant code will become
> 
> : f.n-case-e>0 ( F:fp n e -- )
> \ 3 lines deleted
>      dup >r                          \ n e' r: e'
>      fpad swap type
>      dup 0 >= if '.' emit then       \ n
>      fpad r> +                       \ n fpad+e'
>      swap 0 max type ;
>      
> : f.n-case-e<=0 ( F:fp n e -- )
> \ 3 lines deleted
>      dup >r                          \ n e' r: e'
>      ." 0." abs 0 ?do '0' emit loop
>      fpad swap r> +                  \ fpad n+e'
>      type ;
>      
> : f.n ( F:fp n -- )
>      fdup fpad 32 represent          \ find exp and sign
>      swap .sign fabs \ if '-' emit fabs then      \ print the sign
>      0= if 2drop fdrop
>            fpad 3 type exit then     \ print nan or inf
>      over 0< if
>          swap over 1- negate max swap else   \ limit negative n
>          swap over 1024 swap - min swap then \ limit positive n
>      2dup 0 <= swap 0= and             \ n e f
>      if 2drop   f.n-case-00 exit then
>      2dup + 0<
>      if drop f.n-case-e+n<0 exit then
>      2dup + 0=
>      if  f.n-case-e+n=0 exit then
> \ the 3 lines added here
>      over +  1 max                        \ n e+n
>      fpad 1024 '0' fill
>      fpad swap represent 2drop               \ n e'
> 
>      dup 0>
>      if  f.n-case-e>0 exit then
>      f.n-case-e<=0 ;
> 
> The same changes need to be done on the (f.n) words
> 
> Now also this case will round correctly
> 
> 0.999955555e 2 f.n  1.00
> 
> BR
> Peter
> 
> 

Would you please attach the complete code when you get a chance since 
several revisions have been made?

Also, I found the following issue with n < 0. It's possible I introduced 
a bug in my revisions of your code, or that I missed some change.

0.1e -1 (f.n) type 0.1 ok  \ should be "0."
0.01e -1 (f.n) type 0.01 ok \ should be "0."
0.1e -2 (f.n) type 0.1 ok  \ should be "0."

and similar.

--
Krishna

Technical Details
Message-ID: <11a88oh$3t0ti$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <119oin2$26n99$1@dont-email.me> <11a01mr$sqrm$1@dont-email.me> <20261005150222.00006cf5@tin.it> <11a16nc$1camn$1@dont-email.me> <20261006080347.00002cdf@tin.it> <11a4tj5$2ku7v$1@dont-email.me> <20261007223526.000065ab@tin.it> <6ac7013a$1@news.ausics.net> <20261008121302.00007412@tin.it> <20261008152645.00001682@tin.it>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Krishna Myneni <krishna.myneni@ccreweb.org>
Newsgroups: comp.lang.forth
Subject: Re: F.N floating point format word
Date: Thu, 8 Oct 2026 09:18:57 -0500
Organization: A noiseless patient Spider
Lines: 108
Message-ID: <11a88oh$3t0ti$1@dont-email.me>
References: <119oin2$26n99$1@dont-email.me> <11a01mr$sqrm$1@dont-email.me>
 <20261005150222.00006cf5@tin.it> <11a16nc$1camn$1@dont-email.me>
 <20261006080347.00002cdf@tin.it> <11a4tj5$2ku7v$1@dont-email.me>
 <20261007223526.000065ab@tin.it> <6ac7013a$1@news.ausics.net>
 <20261008121302.00007412@tin.it> <20261008152645.00001682@tin.it>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 08 Oct 2026 14:18:58 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="4096946"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/2Inh3Lc1qJvHr8+Oxp78i"; posting-host="2719ee4311593aa901b5aaaf2caa5538"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:2/MYj+gp/pOtD3ziJhRyMY/skCc= sha256:Qdh+fkvShcxMl1eUDXW3ZVoGo8bWPpASiF2Vv9vnIy4=
	sha1:APbqj2i5jx/Jih+L7e2Cq1UnP10= sha256:ZPzNPeqjMSb2gjuh3t55yoIDqg75N/sxmQ3oEzuLDb8=
In-Reply-To: <20261008152645.00001682@tin.it>
Content-Language: en-US