On Saturday, 18 October 2014 at 08:21:47 UTC, eles wrote:
On Saturday, 18 October 2014 at 05:54:01 UTC, Ola Fosheim Grøstad wrote:
On Saturday, 18 October 2014 at 04:35:07 UTC, Walter Bright wrote:

Larger mantissa can help a little bit, but only a little bit.

https://en.wikipedia.org/wiki/Kahan_summation_algorithm

Kahan helps a little bit:


a = [math.pi*(n**9) for n in range(0,101)]
      +[-math.pi*(n**9) for n in range(100,0,-1)]

print sum(a), kahan(a), fsum(a)

-1389.4713685 239.156561184 0.0


but not a lot:


a = [1e16,math.pi,-1e16]

print sum(a), kahan(a), fsum(a)

4.0 4.0 3.14159265359


a = [1e17,math.pi,-1e17]

print sum(a), kahan(a), fsum(a)

0.0 0.0 3.14159265359

Reply via email to