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


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

Re: sum accuracy

Started byPeter Otten <__peter__@web.de>
First post2016-04-13 19:03 +0200
Last post2016-04-13 19:03 +0200
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 Peter Otten <__peter__@web.de> - 2016-04-13 19:03 +0200

#106962 — Re: sum accuracy

FromPeter Otten <__peter__@web.de>
Date2016-04-13 19:03 +0200
SubjectRe: sum accuracy
Message-ID<mailman.86.1460567115.15650.python-list@python.org>
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.

If you are worried about accuracy and your values are floating point numbers 
use math.fsum():

"""
fsum(...)
    fsum(iterable)
    
    Return an accurate floating point sum of values in the iterable.
    Assumes IEEE-754 floating point arithmetic.
"""

[toc] | [standalone]


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


csiph-web