Using fractions instead of floats

Arnaud Delobelle arnodel at googlemail.com
Tue Oct 2 12:42:24 EDT 2007


On Oct 2, 12:42 pm, Neil Cerutti <horp... at yahoo.com> wrote:
> On 2007-10-01, Arnaud Delobelle <arno... at googlemail.com> wrote:
> > Scheme has prefix numeric operators, so that 1/2 is
> > unambiguously (for the interpreter and the user) a litteral for
> > 'the fraction 1/2'. You can't avoid the confusion in python, as
> > binary operators are infix. Of course, we could create a new
> > kind of litteral.  Let's see, / and // are already operators,
> > so why not use /// ? ;)
>
> But you wouldn't actually need a literal rational represention.

In which case rationals are better off in a module than in the
language!

> But I'm just playing Devil's Advocate here; I like rationals in
> Scheme and Lisp, but I don't see a need for them in Python.

> On the other hand, Python has had complex numbers a long time,
> and it doesn't need those more than rationals, does it? My guess
> is that it got complex numbers but not rationals because
> rationals just aren't very efficient.

Another guess could be that real numbers being closed under the four
arithmetic operations, there is no danger to accidentally step into
complex numbers. OTOH floats and rationals are two (conflicting) ways
of extending integers.

> But as a programmer, I'm mostly just a data-twiddler, and don't
> generally need either of those numeric type in my day-to-day
> work. So I'm not the guy to ask. ;)

I use rationals a lot, and I don't want them in the language :)

--
Arnaud





More information about the Python-list mailing list