Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106962
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: sum accuracy |
| Date | 2016-04-13 19:03 +0200 |
| Organization | None |
| Message-ID | <mailman.86.1460567115.15650.python-list@python.org> (permalink) |
| References | <570E78F9.8050409@chamonix.reportlab.co.uk> <nelu4b$en2$2@ger.gmane.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.
"""
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: sum accuracy Peter Otten <__peter__@web.de> - 2016-04-13 19:03 +0200
csiph-web