Please help - get average

Josiah Carlson jcarlson at uci.edu
Wed Oct 27 11:19:32 EDT 2004


Robin Becker <robin at SPAMREMOVEjessikat.fsnet.co.uk> wrote:
> 
> ...... interestingly the standard algorithms for means/deviations are 
> numerically poor. As an example
> 
>  >>> (1.e30+1-1.0e30)/3
> 0.0
> 
> Where we have total loss of information in one of the terms.
> 
> 
> There are better algorithms involving recursion,

The standard algorithms are only limited by the precision of your
numbers.  If your numbers have poor precision, your result will have
poor precision.

In IEEE 754 FP doubles (like Python uses), you get 53/54 bits of
precision, which is 17 decimal digits.  Reasonable for some things,
unreasonable for others.


> However, in the case of widely differing magnitudes I think you need to 
> accumulate the sums specially.

Yes, you use the forthcoming Decimal module with precision set to your
desired precision.

 - Josiah




More information about the Python-list mailing list