Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73841
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: 1-0.95 |
| Date | 2014-07-02 19:59 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <8761jflms2.fsf@elektro.pacujo.net> (permalink) |
| References | <mailman.11388.1404254753.18130.python-list@python.org> <53b424d7$0$29985$c3e8da3$5496439d@news.astraweb.com> |
Steven D'Aprano <steve+comp.lang.python@pearwood.info>:
> This is a problem with the underlying C double floating point format.
> Actually, it is not even a problem with the C format, since this
> problem applies to ANY floating point format, consequently this sort
> of thing plagues *every* programming language (unless they use
> arbitrary-precision rationals, but they have their own problems).
Actually, it is not a problem at all. Floating-point numbers are a
wonderful thing.
> This works because the Decimal type stores numbers in base 10, like you
> learned about in school, and so numbers that are exact in base 10 are
> (usually) exact in Decimal.
Exactly, the problem is in our base 10 mind. Note, however:
>>> Decimal(1) / Decimal(3) * Decimal(3)
Decimal('0.9999999999999999999999999999')
Even "arbitrary-precision" rationals would suffer from the same problem:
>>> Rational(2).sqrt() * Rational(2).sqrt() == Rational(2)
False
Yes, I'm making it up, but it's still true.
Marko
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
1-0.95 Pedro Izecksohn <izecksohn@yahoo.com> - 2014-07-01 14:17 -0700
Re: 1-0.95 pecore@pascolo.net - 2014-07-02 01:13 +0200
Re: 1-0.95 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-02 15:27 +0000
Re: 1-0.95 Marko Rauhamaa <marko@pacujo.net> - 2014-07-02 19:59 +0300
Re: 1-0.95 Skip Montanaro <skip@pobox.com> - 2014-07-02 12:34 -0500
Re: 1-0.95 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-02 18:34 +0000
Re: 1-0.95 Marko Rauhamaa <marko@pacujo.net> - 2014-07-02 23:00 +0300
Re: 1-0.95 Chris Angelico <rosuav@gmail.com> - 2014-07-03 10:16 +1000
Re: 1-0.95 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-03 02:19 +0000
Re: 1-0.95 Rustom Mody <rustompmody@gmail.com> - 2014-07-02 21:06 -0700
Re: 1-0.95 Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-07-03 16:55 +1200
Re: 1-0.95 Rustom Mody <rustompmody@gmail.com> - 2014-07-02 22:21 -0700
Re: 1-0.95 Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-02 23:50 -0600
OT: speeds (physical, not computing) [was Re: 1-0.95] Steven D'Aprano <steve@pearwood.info> - 2014-07-03 09:15 +0000
Re: 1-0.95 Marko Rauhamaa <marko@pacujo.net> - 2014-07-03 09:51 +0300
Re: 1-0.95 Steven D'Aprano <steve@pearwood.info> - 2014-07-03 09:36 +0000
Re: 1-0.95 Marko Rauhamaa <marko@pacujo.net> - 2014-07-03 14:17 +0300
csiph-web