Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107039
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
| Newsgroups | comp.lang.python |
| Subject | Re: sum accuracy |
| Date | Fri, 15 Apr 2016 11:10:36 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 26 |
| Message-ID | <87d1prw5b7.fsf@bsb.me.uk> (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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="1809"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+I7P7vlCUPaGHEuwR0I8avos3JUk/uiik=" |
| Cancel-Lock | sha1:nsotTRr1vxx8ySKt8QFymCmK23c= sha1:81h6dhzLTTl4mSYSukEB/du0wKg= |
| X-BSB-Auth | 1.0098f6056fb33d27bf68.20160415111036BST.87d1prw5b7.fsf@bsb.me.uk |
| Xref | csiph.com comp.lang.python:107039 |
Show key headers only | View raw
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. -- Ben.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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