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

Antoine Pitrou solipsis at pitrou.net
Sun Sep 26 14:25:29 CEST 2010


On Sun, 26 Sep 2010 22:07:50 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Sun, Sep 26, 2010 at 9:05 PM, Mark Dickinson <dickinsm-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> 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 :)

At the cost of even more execution overhead? :)

Regards

Antoine.





More information about the Python-ideas mailing list