[Python-3000] Math in Python 3.0

Georg Brandl g.brandl at gmx.net
Sun May 14 19:11:54 CEST 2006


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



More information about the Python-3000 mailing list