Jump to content

Averages/Arithmetic mean: Difference between revisions

(add E example. also lang tag forth)
Line 356:
avg = sum / n;
end
 
=={{header|M4}}==
M4 handle only integers, so in order to have a slightly better math for the mean, we
must pass to the <tt>mean</tt> macro integers multiplied by 100. The macro
<tt>rmean</tt> could embed the macro <tt>fmean</tt> and <tt>extractdec</tt>
directly, but it is a little bit clearer to keep them separated.
 
<lang m4>define(`extractdec', `ifelse(eval(`$1%100 < 10'),1,`0',`')eval($1%100)')dnl
define(`fmean', `eval(`($2/$1)/100').extractdec(eval(`$2/$1'))')dnl
define(`mean', `rmean(`$#', $@)')dnl
define(`rmean', `ifelse(`$3', `', `fmean($1,$2)',dnl
`rmean($1, eval($2+$3), shift(shift(shift($@))))')')dnl</lang>
<lang m4>mean(0,100,200,300,400,500,600,700,800,900,1000)</lang>
 
=={{header|MAXScript}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.