Fredrik Johansson wrote:
> For example, square roots are known as math.sqrt(x) for floats,
> cmath.sqrt(x) for complex numbers, x.sqrt() for decimals, and
> gmpy.sqrt(x)/gmpy.fsqrt(x) for gmpy's types. Oh, and SciPy has its own
> sqrt function that works on arrays (but not Decimals or gmpy's types).

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.

Cheers,
Nick.

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
[email protected]
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