Sujet : Re: Average of a [stack]
De : buzz_mccool (at) *nospam* yahoo.com (Buzz McCool)
Groupes : comp.lang.forthDate : 11. Jul 2024, 17:35:40
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6p1ku$2hr48$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
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.
: FloatStackAvg
fdepth dup >r
begin 1- dup while
f+
repeat drop
r> s>f f/
; ok
0.120000e 0.118025e 0.118925e 0.120050e 0.119000e 0.122000e 0.120175e 0.120150e 0.118925e 0.121775e ok f:10
FloatStackAvg ok f:1
fe. 119.902500000000E-3 ok