[Python-3000] Math in Python 3.0

Giovanni Bajo rasky at develer.com
Sun May 14 13:16:02 CEST 2006


Martin v. Löwis <martin at v.loewis.de> 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)
>>
>> @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.


"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.

Giovanni Bajo



More information about the Python-3000 mailing list