This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/16303] [gfortran] Complex logarithm function sometimes chooses a non-principal branch


------- Additional Comments From jblomqvi at cc dot hut dot fi  2004-07-03 08:46 -------
Umm, no. It has to be a problem with gfortran (famous last words...).

I simplified the example a little and made the equivalent C99 program. Consider

program logarithm
  implicit none
  integer, parameter :: dp = selected_real_kind(15, 307)
  real(dp) :: r
  complex(dp) :: z
  complex(dp) :: x
  r = real(1, dp)/1000_dp
  z = (0, -1)*r
  x = (0,1)*r
  print *, 'Following results should within fp precision be: 
(-6.907755,+-1.570796)'
  print *, 'negative cmplx arg: ', log(z) ! gfortran doesn't chose the principal
branch here!
  print *, 'log using cut and paste neg cmplx arg: ', log((0_dp    
,-1.000000000000000E-003))
  print *, 'positive arg: ', log(x)

end program logarithm

and the C99 program

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

int main(void)
{
  double r = 1./1000.;
  double complex z, x;
  z = clog(0. + r*I);
  x = clog(0. - r*I);
  printf("Positive cmplx arg: ( %f, %f )\n", creal(z), cimag(z));
  printf("Negative cmplx arg: (%f, %f)\n", creal(x), cimag(x));
}

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16303


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]