Newsgroups: comp.lang.forth
From: Andrew Haley <andre...@littlepinkcloud.invalid>
Date: Wed, 09 May 2012 06:57:47 -0500
Local: Wed, May 9 2012 7:57 am
Subject: Re: Incremental Averaging
Arnold Doray <inva...@invalid.com> wrote:
It needs a bit of factoring, and I think you're doing too much on the
> Dear Forthers, > I need to do incremental averaging. I came up with this: > : (average) ( n An Xn+1 -- n+1 An+1 )
> : average ( seq -- d )
> REDUCE is a higher order function that takes a stream/"seq", a set of > Note that in this Forth / also handles floating point division. > My problem is that (AVERAGE) looks really ugly. Any suggestions for stack. It's easy if you make the accumulator a structure in memory with count and average, like so: 0
and then:
\ Increment a counter, return its value
\ Incremental average
This will also mean less stack thrashing in the word that calls
Andrew.
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||