Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73882
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: 1-0.95 |
| Date | 2014-07-03 09:51 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <87zjgrdjew.fsf@elektro.pacujo.net> (permalink) |
| References | (1 earlier) <53b424d7$0$29985$c3e8da3$5496439d@news.astraweb.com> <8761jflms2.fsf@elektro.pacujo.net> <53b4509a$0$29985$c3e8da3$5496439d@news.astraweb.com> <878uobpm40.fsf@elektro.pacujo.net> <53b4bdb2$0$29985$c3e8da3$5496439d@news.astraweb.com> |
Steven D'Aprano <steve+comp.lang.python@pearwood.info>: > On Wed, 02 Jul 2014 23:00:15 +0300, Marko Rauhamaa wrote: >> Steven D'Aprano <steve+comp.lang.python@pearwood.info>: >>>> >>> Rational(2).sqrt() * Rational(2).sqrt() == Rational(2) >>>> False >>> Square root of 2 is not a rational number. >> Nobody said it was. > > Your comment can be read as implying it. You stated: > > [quote] > Even "arbitrary-precision" RATIONALS [emphasis added] would > suffer from the same problem > [end quote] > > and then showed an invented example where you squared a NON-RATIONAL. While √2 is irrational, the hypothetical Rational(2).sqrt() probably would be another "arbitrary-precision" Rational number and thus, necessarily an approximation. That's completely analogous to Decimal(1) / Decimal(3) being an approximation. And the point: when dealing with real numbers on a computer, there's no way to avoid approximations. If an aspiring programmer is dismayed at the imprecision of 0.1, that probably wouldn't be the right moment to talk about Decimal(). > By the way, there's no need to use an invented example. Here is an > actual example: > > py> import math > py> from fractions import Fraction > py> math.sqrt(Fraction(2))**2 > 2.0000000000000004 Sure, although you were invoking "arbitrary-precision" rational numbers, which Fraction() is not. > I'm sorry Marko, have you not being paying attention? Have you ever > done any numeric programming? Your style is consistent and impeccable. > Floating-point is *hard*, not "perfect". It can be both. The point is, regular floating point numbers will likely the optimal choice for your numeric calculation needs. They are compact, fast and readily supported by hardware and numeric software. Switching to Decimal might give you a false sense of security. 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