Re: Average of a [stack]

Liste des GroupesRevenir à cl forth 
Sujet : Re: Average of a [stack]
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forth
Date : 12. Jul 2024, 04:53:00
Autres entêtes
Organisation : Ausics - https://newsgroups.ausics.net
Message-ID : <6690a89a$1@news.ausics.net>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
On 12/07/2024 2:35 am, Buzz McCool wrote:
On 7/10/2024 8:31 PM, dxf wrote:
Simpler to count down.  I find it easier writing for a common-stack model.
>
: FloatStackAvg ( rn ... r -- avg )
   fdepth dup >r ( count)
   begin  1- dup while ( not done)
     >r  f+ ( add two floats)  r>
   repeat  drop
   r> s>f f/ ( sum/count)
;
>
 
Thanks for sharing.
 
What is the purpose of putting something on and then off the return stack on this line?
      >r  f+ ( add two floats)  r>
 
Your example word seemed to work fine without it.

Traditionally floats existed on the data stack along with integers, doubles etc.
This required being sensitive to what was on top of the stack.  As time passed some
argued floats should have their own stack.  That's now progressed to Forth-200x
outlawing floats on the data stack.  Implementing a separate float stack is usually
no issue for 16-bit processors and above but for 8-bit cpu's it's prohibitive.
My observation is the same people that push for locals also push for floats on a
separate stack using essentially the same argument.

Date Sujet#  Auteur
10 Jul 24 * Re: Average of a [stack]28Buzz McCool
11 Jul 24 +* Re: Average of a [stack]10dxf
11 Jul 24 i`* Re: Average of a [stack]9Buzz McCool
12 Jul 24 i `* Re: Average of a [stack]8dxf
12 Jul 24 i  `* Re: Average of a [stack]7Buzz McCool
15 Jul 24 i   `* Re: Average of a [stack]6Buzz McCool
18 Jul 24 i    `* Re: Average of a [stack]5minforth
18 Jul 24 i     `* Re: Average of a [stack]4Buzz McCool
18 Jul 24 i      +- Re: Average of a [stack]1minforth
19 Jul 24 i      `* Re: Average of a [stack]2dxf
19 Jul 24 i       `- Re: Average of a [stack]1Buzz McCool
11 Jul 24 +* Re: Average of a [stack]16dxf
11 Jul 24 i`* Re: Average of a [stack]15ahmed
11 Jul 24 i `* Re: Average of a [stack]14ahmed
11 Jul 24 i  `* Re: Average of a [stack]13minforth
11 Jul 24 i   `* Re: Average of a [stack]12ahmed
11 Jul 24 i    +- Re: Average of a [stack]1ahmed
11 Jul 24 i    `* Re: Average of a [stack]10minforth
11 Jul 24 i     `* Re: Average of a [stack]9ahmed
11 Jul 24 i      +- Re: Average of a [stack]1minforth
14 May 25 i      `* Re: Average of a [stack]7anthk
14 May 25 i       `* Re: Average of a [stack]6ahmed
14 May 25 i        +- Re: Average of a [stack]1ahmed
15 May 25 i        `* Re: Average of a [stack]4dxf
15 May 25 i         +* Re: Average of a [stack]2Hans Bezemer
15 May 25 i         i`- Re: Average of a [stack]1dxf
15 May 25 i         `- Re: Average of a [stack]1Hans Bezemer
12 Jul 24 `- Re: Average of a [stack]1Anton Ertl

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal