Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: 1-0.95 Date: Wed, 02 Jul 2014 19:59:25 +0300 Organization: A noiseless patient Spider Lines: 29 Message-ID: <8761jflms2.fsf@elektro.pacujo.net> References: <53b424d7$0$29985$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx05.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="20779"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tjXjQaZaG/m8OgDAalYr0" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:XIgB2ksNAcSO/8H+ivpsWP0fB7E= sha1:+L/qSqae2osxtAlseTSDan7C1T8= Xref: csiph.com comp.lang.python:73841 Steven D'Aprano : > 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