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


Groups > comp.lang.python > #106961

Re: sum accuracy

From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: sum accuracy
Date 2016-04-13 13:05 -0400
Message-ID <mailman.85.1460567112.15650.python-list@python.org> (permalink)
References <570E78F9.8050409@chamonix.reportlab.co.uk> <1460567110.3933817.577783969.165F6097@webmail.messagingengine.com>

Show all headers | View raw


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)

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web