proposed language change to int/int==float (was: PEP0238 lame nt)

Delaney, Timothy tdelaney at avaya.com
Wed Jul 25 02:55:57 EDT 2001


> > The interesting thing is that the one thing that has to change in
> > order to get a unified numeric model, whether we introduce rationals
> > in the numeric tower or not, is integer division!  A numeric tower
> > with rationals could look like this:
> >
> >   int < long < rational < float < complex
> >
>   Just a comment: What bothers me is that floats in computers
> are not the
> same as R continuum im math. This makes me think that
> rationals are "better"
> than floats. Indeed, any float number can be exactly represented by
> rational, but not vice virsa.  So my tower would be like that:
>
> int < long < float < rational < complex float < complex rational

I'm going to assume the unification of ints and longs here ...

The problem that we have is that long and rational would have a greater
range than float, as they are effectively unbounded in size (ignoring memory
restrictions of course).

I'm starting to think the rational term is incorrect. We could get rid of
the above problem by having a "denominated" type.

A "denominated" type is represented as long or float numerator, long or
float denominator. So long as both the numerator and denominator are within
the range of float, the "denominated" number can be as large as you wish.

Complex of course could have its real and imaginary parts being long, float
or denominated.

We would then have a tree like ...

long < float iff long in range of float
long < denominated
float < denominated
denominated < complex

So, to perform an operation on long and float, the following promotions (and
demotions) would occur.

1. Promote long to denominated => long/1
2. Promote float to denominated => float/1
3. Perform operation
4. If the result is in the range of float, demote to float.

There are a couple of optimisations possible here, such as promoting a long
to float and performing the operation, but if the result is greater than the
float can represent it will need to then be promoted to denominated anyway.

Tim Delaney




More information about the Python-list mailing list