complex numbers

Anno Siegel anno4000 at lublin.zrz.tu-berlin.de
Tue Jan 11 20:00:29 CET 2005


It's me <itsme at yahoo.com> wrote in comp.lang.perl.misc:

[reply moved into context]

> "Anno Siegel" <anno4000 at lublin.zrz.tu-berlin.de> wrote in message
> news:cs145l$8d6
> 
> <snip>
> 
> >
> > Like this?
> >
> >     use Math::Complex;
> >
> >     my $z = sqrt( -1);
> >     print 1 + $z, "\n"; # prints "1+i"
> >
> > Operator overloading makes it possible to work with complex numbers as if
> > they were a native data type.

> Operator overloading (and function overloading) helps but not enough.    You
> have to be aware of the complex type *everywhere* you go and that's very
> annoying and error prone.  I've been the works with C++, and later with
> Modelica.   I am very happy that Python included *native* complex number
> support.

What kind of awareness do you mean?

There are some operations (as comparison) that work for reals, but not
for complex numbers.  If you want your program to run with complex input,
you have to avoid such operations, whether the data type is native or not.

What other considerations are there?  A typical numeric program should
just run and give complex output when fed complex input.  I made the
experiment with the Perl module Statistics::Descriptive, which was
certainly written without concern for complex input, and it works without
a hitch.  I'm not sure if the (complex) variance of several complex
numbers is a reasonably interpretable quantity, but I'm certain the
maths is done right.  What else do you want?

Anno



More information about the Python-list mailing list