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

Relevant Pages

  • Re: HPGCC Questions ladies and gentlemen!!!
    ... :> how to compile it, and that means learning how to use the tools. ... Where did you get the gcc package for windows from? ... :> bit looking for bugs in their beginer level programs with the use of printf ... What kind of program written by beginner is going to "crash"? ...
  • Re: Disable printf
    ... I guess the gcc doesn't know how to handle the std c lib if you ... idea to disable all printf statements so that less memory is required. ... included common header. ...
  • Re: Making LLVM happy: memmove() in the kernel
    ... be copied by memcpy() which should be faster. ... since _all_ gcc builtins were turned off many years as a side effect ... The gcc builtin for printf() sometimes translates printfto use ...
  • Re: x86-64 assembly problems
    ... yasm assembler and link with the gcc. ... in the way simple functions like printf() work with assembly in 64bit ... dword string1; gcc does this when it calls ...
  • Re: [kde] Problem compiling extragear/graphics/digikam/libs/dmetadata/loaders/dmetaloader.cpp
    ... I am running Fedora Core 5. ... Are you using GCC 4.x? ... In that case you'd better file a bug report ... Steps to Reproduce: ...