[Python-3000] Math in Python 3.0

"Martin v. Löwis" martin at v.loewis.de
Sun May 14 13:40:02 CEST 2006


Giovanni Bajo wrote:
>>> @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)
>>>
>> So where would that sqrt function live?
> 
> "math" would be fine for all builtin types. For other types, imported from
> modules, such as numpy, they could add their overload to math.sqrt at
> import-time.

That wouldn't quite work: sqrt(float) would cause a stack overflow for
calling itself.

In any case, I still wonder whether these functions should be unified
when they have different semantics (e.g. when passing negative ints or
floats to math.sqrt vs. cmath.sqrt).

Regards,
Martin


More information about the Python-3000 mailing list