[Python-ideas] Including elementary mathematical functions in the python data model

Nick Coghlan ncoghlan at gmail.com
Sun Sep 26 14:07:50 CEST 2010


On Sun, Sep 26, 2010 at 9:05 PM, Mark Dickinson <dickinsm at gmail.com> wrote:
> A less invasive proposal would be just to introduce __sin__, etc.
> magic methods and have math.sin delegate to <type>.__sin__;  i.e.,
> have math.sin work in exactly the same way that math.floor and
> math.ceil currently work.  That would be quite nice for e.g., the
> decimal module:  you'd be able to write something like:
>
> from math import sqrt
> root = (-b + sqrt(b*b - 4*a*c)) / (2*a)
>
> to compute the root of a quadratic equation, and it would work
> regardless of whether a, b, c were Decimal instances or floats.
>
> I'm not sure how I feel about the entailed magic method explosion, though.

Couple that with the extra function call overhead (since these
wouldn't have real typeslots) and it still seems like a less than
stellar idea.

As another use case for solid, efficient generic function support
though... great idea :)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list