A rational proposal

Mike Meyer mwm at mired.org
Sat Dec 18 13:29:10 EST 2004


"Raymond L. Buvel" <levub137 at wi.rr.com> writes:

> Mike Meyer wrote:
>> PEP: XXX
>> Title: A rational number module for Python
> <snip>
>
> I think it is a good idea to have rationals as part of the standard
> distribution but why not base this on the gmpy module
> (https://sourceforge.net/projects/gmpy)?  That module already provides
> good performance.  However, it does a few things that may not be good
> ideas.

It wraps a third party package, which can't really be added to the
standard libraray. The documentation for a rationa number package in
Python should include a pointer to gmpy with a note about performance.

> 3. Fractional powers fail with a ValueError if the root is not
> exact. You do not address this in your proposal.  Could silently
> convert to float in this case but is it better to force the user to be
> explicit and use the float() operation?

You're right. Raising a rational to a rational power isn't covered,
and may produce an irrational answer. Raising a rational to a floating
point power will cause the rational to be converted to a float, as is
specified.

I think forcing the use of float is wrong, as the rational may be an
integer. I'm not sure what should be done, so this is being added as
an open issue.

   Thanks,
   <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list