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


Groups > comp.lang.python > #106961

Re: sum accuracy

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: sum accuracy
Date Wed, 13 Apr 2016 13:05:10 -0400
Lines 16
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>
Mime-Version 1.0
Content-Type text/plain
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de kn0zQb7CxKc9RQnHQQTjZASTY3MMIe1HV+ApnJvx8JfQ==
Return-Path <random832@fastmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.016
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'operator': 0.03; '(except': 0.05; 'received:internal': 0.09; 'wed,': 0.15; 'assumptions': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'semantically': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'tests': 0.18; 'algorithm': 0.20; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'equivalent': 0.27; '13,': 0.29; 'types.': 0.29; 'url:activestate': 0.29; 'anyone': 0.32; "can't": 0.32; 'point': 0.33; 'url:code': 0.34; 'that,': 0.34; 'but': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'seem': 0.37; 'no,': 0.38; 'received:66': 0.38; 'anything': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'header:Message-Id:1': 0.61; 'show': 0.62; 'real': 0.62; 'more': 0.63; 'sum': 0.69; 'special': 0.73; 'algorithm,': 0.84; 'becker': 0.84; 'strings),': 0.84; 'url:recipes': 0.84
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=lArsGJtF0PoedbWPuhua2moDfLg=; b=bzxmwf fbyZmYQy28L047DnUUHSM8zGYDbrpeoNQoeRUDVMjbrWYPtncPqcdSClyQi9qd9h PD1+urTKq5iGZFTXVIQZ6Yyvp/GvikhYZ7exTZRWJjC8pAaluhyXytqnO3NZsEWN 9fFuTmSL4sflGuQzf9Gxr6GMvId4CnGI2L11g=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=lArsGJtF0PoedbW Puhua2moDfLg=; b=Agy+Uq83chBIq5ehcAtzL6f9ahXg8Rri/D7uGOLLmJlen3M kK6g4IKeWUEhLDY7Dcb3INk6pYmKfFoL4rBrjt+l+tYhOBZ5bB37gJI847NsVCTr DDIVVo9GrExmxustKvxpJsDU/fVHZiQBnS0ZImEddrDA6iOue8zl586Mf0lk=
X-Sasl-Enc gq7ehRqlk6Y/oOsKUD0cyMpv5ODcL2yD01bnKBAuVZ9c 1460567110
X-Mailer MessagingEngine.com Webmail Interface - ajax-7bc02efc
In-Reply-To <570E78F9.8050409@chamonix.reportlab.co.uk>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <1460567110.3933817.577783969.165F6097@webmail.messagingengine.com>
X-Mailman-Original-References <570E78F9.8050409@chamonix.reportlab.co.uk>
Xref csiph.com comp.lang.python:106961

Show key headers only | 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