Rational Numbers
Carsten Haese
carsten at uniqsys.com
Fri Jan 12 10:36:38 EST 2007
On Fri, 2007-01-12 at 15:05 +0000, Nick Maclaren wrote:
> In article <mailman.2643.1168611301.32031.python-list at python.org>,
> Carsten Haese <carsten at uniqsys.com> writes:
> |> On Thu, 2007-01-11 at 23:47 +0000, Nick Maclaren wrote:
> |> > In article <mailman.2597.1168550439.32031.python-list at python.org>,
> |> > Facundo Batista <facundo at taniquetil.com.ar> writes:
> |> > |> Python does not have rational numbers.
> |> > |>
> |> > |> There's a (rejected) PEP about this, PEP-239:
> |> > |>
> |> > |> http://www.python.org/dev/peps/pep-0239/
> |> > |>
> |> > |> Maybe you also want to read the section "Why not rational?" of
> |> > |> PEP-327...
> |> > |>
> |> > |> http://www.python.org/dev/peps/pep-0327/#why-not-rational
> |> >
> |> > Oh, God. Decimal delusions again :-(
> |> >
> |> > There are good arguments for not having a rational type, but the idea
> |> > that decimal floating-point is in any way a replacement is cuckoo.
> |>
> |> You're putting words in Facundo's mouth. Facundo didn't say why we
> |> should read that section of PEP 327. I think he merely pointed to the
> |> slow performance of rational numbers that's explained in that section.
> |> (Facundo is the author of PEP 327, so I find it unlikely that he has
> |> delusions about what decimals can and can't do.)
>
> You're putting words in MY mouth! I didn't say that he did. But I
> agree that my words could easily be read that way, so I apologise for
> any misunderstanding.
> [...]
> The BDFL Pronouncement rejecting PEP 239 does, even if it does qualify
> it by saying "to some extent". And it was that PEP that I was primarily
> referring to in that remark.
Ah, so now you're putting words in the BDFL's mouth. ;)
The pronouncement does say "The needs outlined in the rationale section
have been addressed to some extent by the acceptance of PEP 327 for
decimal arithmetic," but it doesn't say to which extent, and it
certainly doesn't claim that decimal arithmetic is a replacement for
rational arithmetic.
> The "Why not rational?" section of PEP 327 quotes Alex Martelli as saying
> that Rational are not worth doing without Decimal, which makes no sense
> at all. All it does is to plug Decimal for a purpose for which it is
> completely unsuited; not all rational numbers have denumerators that are
> powers of 10.
The sentence you're referring to is "There are excellent Rational
implementations [...]. Probably worth PEPping, not worth doing without
Decimal." I agree that this sentence is poorly worded, but I think it
means "Even if we had Rational, we'd still need Decimal" in the sense
that Rational is not an adequate replacement for Decimal.
The bottom line is that there are use cases for both Rational and
Decimal, and neither one can replace the other, but there are more use
cases for Decimal than for Rational.
-Carsten
More information about the Python-list
mailing list