# A rational proposal

Dan Bishop danb_83 at yahoo.com
Mon Dec 20 14:19:38 EST 2004

Mike Meyer wrote:
> "John Roth" <newsgroups at jhrothjr.com> writes:
>
> > "Mike Meyer" <mwm at mired.org> wrote in message
> > news:864qik472n.fsf at guru.mired.org...
> >> PEP: XXX
> >> Title: A rational number module for Python
...
> >> Rationals will mix with all other numeric types.  When combined
with an
> >> integer type, that integer will be converted to a rational before
the
> >> operation.  When combined with a floating type - either complex or
> >> float - the rational will be converted to a floating approximation
> >> before the operation, and a float or complex will be returned.
The
> >> reason for this is that floating point numbers - including complex
-
> >> are already imprecise.  To convert them to rational would give an
> >> incorrect impression that the results of the operation are
> >> precise.  Decimals will be converted to rationals before the
> >> operation.  [Open question: is this the right thing to do?]
> >
> > I'd prefer to have rationals converted to decimals before
> > the operation, for the same reason that they're converted
> > to floats. Decimals also have limited precision.
>
> precision. But they represent their values exactly,

The decimal class exactly represents numbers that have exact, concise
representations in decimal, such as monetary amounts.  It doesn't
represent arbitary numbers exactly.  Otherwise, why bother implememting
a rational class?

...
> On the other hand,
> every decimal has a rational equivalent, but not vice versa.
The same statement is true for floats.