[Python-ideas] Add additional special method lookups to math module
Case Van Horsen
casevh at gmail.com
Wed Nov 9 07:17:26 CET 2011
Currently the functions round(), math.ceil(), math.floor(), and
math.trunc() all check for the existence of a special method
(__round__, __ceil__, __floor__, and __trunc__). Would it be possible
to enhance the math and cmath modules to check for the existence of a
special method for (almost) functions? For example, math.sin(obj)
would first check for obj.__sin__.
Rationale
I'm in the final stages of adding support for the MPFR
(multiple-precision floating point) and MPC (multiple-precision
complex) libraries to the next-generation of gmpy, currently known as
gmpy2. If the special method checks are added to the math and cmath
modules, then the new mpfr() and mpc() types can easily substitute for
the existing float/complex types in code that uses the math or cmath
module.
Thoughts?
More information about the Python-ideas
mailing list