Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: sum accuracy Date: Wed, 13 Apr 2016 19:03:06 +0200 Organization: None Lines: 17 Message-ID: References: <570E78F9.8050409@chamonix.reportlab.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de yuBavejdonF9a/bWMaR8oQEjWuc3iCxx3lGayrLzL3lQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '"""': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'arithmetic.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'tests': 0.18; 'assumes': 0.22; 'accuracy': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'equivalent': 0.27; 'values': 0.28; 'anyone': 0.32; 'point': 0.33; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'seem': 0.37; 'anything': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'show': 0.62; 'sum': 0.69; 'special': 0.73; 'becker': 0.84; 'worried': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd9d74.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <570E78F9.8050409@chamonix.reportlab.co.uk> Xref: csiph.com comp.lang.python:106962 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. """