[Python-ideas] Add additional special method lookups to math module

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Nov 10 01:29:13 CET 2011


On 10/11/11 12:02, Steven D'Aprano wrote:

> However, how far should we go? Does every function in the math module require
> a dunder method, e.g. __degrees__ ? What happens if we add more functions, say
> math.bessel?

Another approach to all this would be to provide generic implementations
of the math functions in terms of the basic arithmetic operations. While
this wouldn't always be as fast as using type-specific methods, it would
at least work with all number-like types and would extend easily to any
new functions we might add without having to update every existing
numeric type.

It might even be possible to support type-specific accelerations of these
generic implementations using a __polynomial__ method that takes a list
of coefficients, or maybe a function for generating the coefficients.

-- 
Greg



More information about the Python-ideas mailing list