precision. This has been discussed at http://bugs.python.org/issue1682. It's
useful primarily for teaching, but it also demonstrates how to implement a
member of the numeric tower, including fallbacks for mixed-mode arithmetic.
I expect to write a couple more patches in this area:
* Rational.from_decimal()
* Rational.trim/approximate() (maybe with different names)
* Maybe remove the parentheses from Rational.__str__()
* Maybe rename one of the Rational classes
* Maybe make Rational('3/2') work.
Found them using::
find . -name '*.py' | while read i ; do grep 'def[^(]*( ' $i /dev/null ; done
find . -name '*.py' | while read i ; do grep ' ):' $i /dev/null ; done
(I was doing this all over my own code anyway, because I'd been using spaces in
all defs, so I thought I'd make a run on the Python code as well. If you need
to do such fixes in your own code, you can use xx-rename or parenregu.el within
emacs.)
for non-complex arguments.
* Replace type() comparisons with isinstance() checks.
* Replace apply() calls with equivalent syntactic form.
* Simplify __hash__ definition to hash the underlying tuple.
* Use math.hypot() for more robust computation of __abs__().
* Use sorted() instead of the multi-step keys/sort/iter.
* Update comment on the cmath module.
Cleaned up existing code by abstracting code to parse arguments. Also removed
any unneeded operations (such as calling 'int' on a division when using floor
division also works). Fixed a bug where the values returned by
OldStyleRange could be short by one value. Added more documentation.
Testing code also has a basic sanity check.