Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106961 > unrolled thread

Re: sum accuracy

Started byRandom832 <random832@fastmail.com>
First post2016-04-13 13:05 -0400
Last post2016-04-13 13:05 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: sum accuracy Random832 <random832@fastmail.com> - 2016-04-13 13:05 -0400

#106961 — Re: sum accuracy

FromRandom832 <random832@fastmail.com>
Date2016-04-13 13:05 -0400
SubjectRe: sum accuracy
Message-ID<mailman.85.1460567112.15650.python-list@python.org>
On Wed, Apr 13, 2016, at 12:51, Robin Becker wrote:
> Does anyone know if sum does anything special to try and improve
> accuracy? My 
> simple tests seem to show it is exactly equivalent to a for loop
> summation.

No, it doesn't. Sum works on any type that can be added (except
strings), it can't make any assumptions about the characteristics of
floating point types. For non-numeric types, the addition operator may
not be semantically commutative or associative.

Look at
http://code.activestate.com/recipes/393090-binary-floating-point-summation-accurate-to-full-p/
for an example of a more accurate algorithm, but note that, for example,
this algorithm wouldn't work on complex numbers (you'd have to sum the
real and imaginary components separately)

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web