Martin v. Löwis wrote:
> 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).

I think that cmath should stay separated. It operates on an entirely different
set of numbers, while all the other methods all work on real numbers that
just happen to be represented differently.

Georg

_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to