Re: Complex logarithm



"Steven G. Kargl" <sgk@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

If you use -O on the command line, I suspect you will not see
this issue. AFAICT, the GCC middle-end will evaluates
__builtin_clog(z) at compile time with -O. Without -O, it generates
a function call to the math library's clog(). If your math library does
not include a clog() function, then libgfortran will include a fallback
implementation. This fallback implementation is not very robust.

So, 1) file a bug report with your OS vendor about the missing
clog() function in their libm. 2) file a bug report with GCC.

Different optimizations do not change the result.
I get the same with C. That means the problem is in GCC?
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3

#include <math.h>
#include <complex.h>
#include <stdio.h>

int main ()
{
double x, fx,gx;
double _Complex z, fz,gz;
z = 1.0f + 0.00000001f*_Complex_I;
fz = clog(z);
gz = (z-1) - (z-1)*(z-1)/2;
printf (" %.15e + %.15ei\n", creal(fz), cimag(fz));
printf (" %.15e + %.15ei\n", creal(gz), cimag(gz));
x = 1.00000001;
fx = log(x);
gx = (x-1) - (x-1)*(x-1)/2;
printf (" %.15e\n", fx);
printf (" %.15e\n", gx);
return 0;
}

$ gcc -lm -lc test.c; ./a.out
0.000000000000000e+00 + 9.999999939225290e-09i
4.999999939225290e-17 + 9.999999939225290e-09i
9.999999889225291e-09
9.999999889225291e-09
.