Problems exp'ing complex numbers

Wolfgang Mauerer wolfgang@mynetix.de
Sat Dec 30 15:36:00 GMT 2000


Hi,
Gabriel Dos Reis wrote:
> 
> Do you have a test case?
The following program:

#include <iostream>
#include <complex>

int main()
{
  long_double_complex test (1000,0);

  cout << "test      : " << test << endl;
  cout << "exp(test) : " << exp(test) << endl;
  return 0;
}

results in

test      : (1000,0)
exp(test) : (inf,nan)

If the definition

complex<long double> exp(const complex<long double> x) {
  return polar(expl(real(x)), imag(x));
}

is included into the file, the following result is gained then:

test      : (1000,0)
exp(test) : (1.97007e+434,0)

Obviously, one has to use expl instead of exp for calculating
the exponentiation of the real part. That isn't done
in the standard library, here the normal exp is used
for all data types.
Sorry that I didn't think about including concrete numbers in my first
mail.

Wolfgang


More information about the Libstdc++ mailing list