[Python-3000] Math in Python 3.0

"Martin v. Löwis" martin at v.loewis.de
Sun May 14 08:41:11 CEST 2006


Nick Coghlan wrote:
> Py3k's function overloading should fix this:
> 
> @overloaded
> def sqrt(value):
>     raise TypeError("Cannot take square root of %s" % type(value).__name__)
> 
> @sqrt.overload
> def sqrt_float(value : float):
>     return math.sqrt(value)
> 
> @sqrt.overload
> def sqrt_complex(value : complex):
>     return cmath.sqrt(value)
> 
> @sqrt.overload
> def sqrt_decimal(value : decimal):
>     return value.sqrt()
> 
> # Similar overloads can be added for the types in gmpy and numpy.

So where would that sqrt function live? I hope you are not proposing it
becomes a builtin - I dearly wish there were fewer builtins, not more.

Regards,
Martin


More information about the Python-3000 mailing list