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


Groups > comp.lang.python > #107041

Re: sum accuracy

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Tony van der Hoff <tony@vanderhoff.org>
Newsgroups comp.lang.python
Subject Re: sum accuracy
Date Fri, 15 Apr 2016 11:39:45 +0100
Lines 34
Message-ID <mailman.13.1460717963.6324.python-list@python.org> (permalink)
References <570E78F9.8050409@chamonix.reportlab.co.uk> <1460567110.3933817.577783969.165F6097@webmail.messagingengine.com> <5710B365.5040903@chamonix.reportlab.co.uk> <CAHVvXxSub2Z2j6eedm3zQr7v2aYWMhmGYzXTtx+SPrcAFgXFtw@mail.gmail.com> <mailman.11.1460712984.6324.python-list@python.org> <87d1prw5b7.fsf@bsb.me.uk> <5710C4F1.8050805@vanderhoff.org>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de cz/G6pybmAXRGogE9vPbjASGUa0D197qX3ReGUBP6yQA==
Return-Path <tony@vanderhoff.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.018
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'float': 0.05; 'benjamin': 0.09; 'nameerror:': 0.09; 'rounding': 0.09; 'def': 0.13; '2016': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'numerical': 0.18; 'input': 0.18; '>>>': 0.20; 'fraction': 0.22; 'defined': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'van': 0.26; 'errors.': 0.27; 'helpful.': 0.29; 'convert': 0.29; 'objects': 0.29; "i'm": 0.30; 'error.': 0.31; 'case,': 0.34; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'received:localdomain': 0.38; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'yes': 0.62; 'charset:windows-1252': 0.62; 'becker': 0.84; 'from:addr:tony': 0.84; 'oscar': 0.84; 'received:192.168.1.7': 0.91
X-Virus-Scanned Debian amavisd-new at mail.vanderhoff.org
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.7.0
In-Reply-To <87d1prw5b7.fsf@bsb.me.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 <5710C4F1.8050805@vanderhoff.org>
X-Mailman-Original-References <570E78F9.8050409@chamonix.reportlab.co.uk> <1460567110.3933817.577783969.165F6097@webmail.messagingengine.com> <5710B365.5040903@chamonix.reportlab.co.uk> <CAHVvXxSub2Z2j6eedm3zQr7v2aYWMhmGYzXTtx+SPrcAFgXFtw@mail.gmail.com> <mailman.11.1460712984.6324.python-list@python.org> <87d1prw5b7.fsf@bsb.me.uk>
Xref csiph.com comp.lang.python:107041

Show key headers only | View raw


On 15/04/16 11:10, Ben Bacarisse wrote:
> Oscar Benjamin <oscar.j.benjamin@gmail.com> writes:
>
>> On 15 April 2016 at 10:24, Robin Becker <robin@reportlab.com> wrote:
> <snip>
>>> yes indeed summation is hard :(
>>
>> Not with Fraction it isn't:
>>
>> from fractions import Fraction
>>
>> def exact_sum(nums):
>>      return sum(map(Fraction, nums))
>>
>> This will give you the exact result with precisely zero rounding
>> error. You can convert it to float at the end.
>
> Just a word of warning for people new to numerical work: there's no
> rounding error, but unless you start with Fraction objects you still
> have input or conversion errors.  The uninitiated might expect
>
>    exact_sum([0.3, 0.7])
>
> to be 1.
>

So I'm uninitiated:
NameError: name 'exact_sum' is not defined

I appreciate the word of warning, but, in my case, it's not helpful.

-- 
Tony van der Hoff        | mailto:tony@vanderhoff.org
Buckinghamshire, England |

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


Thread

Re: sum accuracy Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-04-15 10:36 +0100
  Re: sum accuracy Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-04-15 11:10 +0100
    Re: sum accuracy Tony van der Hoff <tony@vanderhoff.org> - 2016-04-15 11:39 +0100
      Re: sum accuracy Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-15 14:31 +0300
    Re: sum accuracy Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-04-15 08:11 -0400
    Re: sum accuracy Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-04-15 14:49 +0100
      Re: sum accuracy Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-04-15 17:54 +0100
    Re: sum accuracy Matt Wheeler <m@funkyhat.org> - 2016-04-15 18:04 +0100

csiph-web