[Numpy-discussion] Importance of order when summing values in anarray

Nadav Horesh nadavh at visionsense.com
Tue Dec 9 10:51:49 EST 2008


As much as I know float128 are in fact 80 bits (64 mantissa + 16 exponent) so the precision is 18-19 digits (not 34)

  Nadav.


-----הודעה מקורית-----
מאת: numpy-discussion-bounces at scipy.org בשם Bruce Southey
נשלח: ג 09-דצמבר-08 17:46
אל: Discussion of Numerical Python
נושא: Re: [Numpy-discussion] Importance of order when summing values in anarray
 
Hanni Ali wrote:
> Hi Bruce,
>
> Ahh, but I would have thought the precision for the array operation 
> would be the same no matter which values I wish to sum? The array is 
> in float64 in all cases.
>
> I would not have thought altering the type of the integer values would 
> make any difference as these indices are all below 5 milllion.
>
> Perhaps I have misunderstood your suggestion could you expand.
>
> Cheers,
>
> Hanni
>
>
>     Also, increase the numerical precision as that may depend on your
>     platform especially given the input values above are ints. Numpy has
>     float128 and int64 that will minimize rounding error.
>
>     Bruce
>     _______________________________________________
>     Numpy-discussion mailing list
>     Numpy-discussion at scipy.org <mailto:Numpy-discussion at scipy.org>
>     http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>   
Hi,
The main issue is the number of significant digits that you have which 
is not the number of decimals in your case. So while the numerical 
difference in the results is in the order about 1.86e-09, the actual 
difference starts at the 15th significant place. This is expected due to 
the number of significant digits of a 64-bit number (15-16). With higher 
precision like float128 you should get about 34 significant digits 
depending accuracy in all steps (i.e., the numbers must be stored as 
float128 and the summations done in float128 precision).

Note there is a secondary issue of converting numbers between different 
types as well as the binary representation of decimal numbers. Also, 
rather than just simple summing, there are alternative algorithms like 
Kahan summation algorithm that can minimize errors.

Bruce




_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 4202 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20081209/63786987/attachment.bin>


More information about the NumPy-Discussion mailing list