[Python-Dev] Re: PEP239 (Rational Numbers) Reference Implementation and new issues (original) (raw)

Christopher A. Craig list-python@ccraig.org
10 Oct 2002 11:19:47 -0400


Tim Peters <tim.one@comcast.net> writes:

If you haven't yet, you should strive to understand Moshe Zadka's prototype rational implementation in Python CVS nondist/sandbox/ (which has all the approximation functions you could need). Unfortunately, the SourceForge Python Numerics list:

https://sourceforge.net/mailarchive/forum.php?forumid=2280 appears to have lost almost all the voluminous discussions that went into that, retaining mostly a random sampling of spam.

I have read the module. I really liked his (your?) trim code and I used that algorithm in cRat and my rational patch. I don't think I'd use any of that for generating decimal (or binary) float approximations, though. Trim introduces some error into the calculation which is then furthered by the float division. You can provably generate the closest scaled long of a given size (and thus hopefully the closest float) with one shift and one long integer division.

-- Christopher A. Craig <list-python@ccraig.org> "It mearly pleases me to behave in a certain way to what appears to be a cat" -- The Ruler of the Universe (The Restaurant at the End of the Universe)