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] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch


Sometimes it seems that the complex logarithm function chooses a non-principal
branch, while the standard specifies (section 13.7.67 in the F2003 draft) that
the principal branch should be taken.

We remeber that the complex logarithm is defined as

log(z) = ln|z| + i[Arg(z) + 2*pi*n] , 

where n is an integer and n = 0 implies the principal branch.

Here is an example program which demonstrates this problem. We see that the n=1
branch is taken in the cases marked in the comments.

program logarithm
  implicit none
  integer, parameter :: dp = selected_real_kind(15, 307)
  real(dp), parameter :: pi = 3.141592653589793238462643383280
  real(dp) :: r
  complex(dp) :: z
  complex :: x
  r = real(1, dp)/1000_dp
  z = r * exp(-5 * (0_dp, 1_dp) * pi / 10_dp)
  x = cmplx(z)
  print *, 'Input to log:'
  print *, 'double precision: ', z
  print *, 'single precision: ', x
  print *, 'Following results should within fp precision be:  (-6.907755,-1.570796)'
  print *, 'double prec log: ', log(z) ! gfortran doesn't chose the principal
branch here!
  print *, 'log using cut and paste arg: ', log((6.123031769111886E-020    
,-1.000000000000000E-003))
  print *, 'single prec log: ', log(x) ! and neither here!

end program logarithm

-- 
           Summary: [gfortran] Complex logarithm function sometimes chooses
                    a non-principal branch
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jblomqvi at cc dot hut dot fi
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-linux-gnu


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]