[Python-3000] Math in Python 3.0

Fredrik Johansson fredrik.johansson at gmail.com
Sat May 13 22:23:41 CEST 2006


On 5/13/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> > It's fine for
> > calculating with nothing but floats, or nothing but ints, but writing
> > code that works for ints, floats, complexes *and* Decimals - let alone
> > for custom types such as mpfs or numeric arrays - is nearly
> > impossible. Duck typing doesn't work because these types all have
> > different interfaces, despite being functionally (or conceptually)
> > equivalent for many purposes.
>
> Why do you say that? To me, it seems that these types have all
> *precisely* the same operations: +, -, *, /.

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

> My guess is that it isn't brought up very often because very few
> people have the problem you are talking about.

Perhaps they don't complain, but that doesn't mean that they wouldn't
appreciate the difference :-)

Fredrik Johansson


More information about the Python-3000 mailing list