Re: Average of a [stack]

Liste des GroupesRevenir à cl forth 
Sujet : Re: Average of a [stack]
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.lang.forth
Date : 12. Jul 2024, 09:06:19
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2024Jul12.100619@mips.complang.tuwien.ac.at>
References : 1 2 3
User-Agent : xrn 10.11
Buzz McCool <buzz_mccool@yahoo.com> writes:
On 6/7/2024 1:32 PM, LIT wrote:
: AVG  DEPTH 0 SWAP DUP >R 0 DO SWAP + LOOP R> / . ;
>
I coincidentally was doing averaging for the floating point stack when I
ran across this posting. Other than adding stack comments, how can I
improve this word?

Eliminate DEPTH, e.g., by replacing it with a count of the elements
you want to average over, or better, write a word that takes only a
descriptor of, e.g., an array in memory, and averages over the array.

Why should DEPTH not be used in this way?  Because it means that AVG_
consumes the whole stack and is useless in a word that keeps some
temporary data deeper in the stack when it calls another word, an
idiomatic way of using Forth.

- anton
--
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: https://forth-standard.org/
   EuroForth 2024: https://euro.theforth.net

Date Sujet#  Auteur
12 Jul 24 o Re: Average of a [stack]1Anton Ertl

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal