public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch
@ 2004-06-30 19:57 jblomqvi at cc dot hut dot fi
  2004-07-01  3:36 ` [Bug fortran/16303] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: jblomqvi at cc dot hut dot fi @ 2004-06-30 19:57 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/16303] [gfortran] Complex logarithm function sometimes chooses a non-principal branch
  2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
@ 2004-07-01  3:36 ` pinskia at gcc dot gnu dot org
  2004-07-03  8:46 ` jblomqvi at cc dot hut dot fi
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-01  3:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-07-01 03:36 -------
hmm, this looks like not to be a gfortran problem at all.
it is only calling clog:
  _gfortran_transfer_character ("double prec log: ", 17);
  T.0 = clog (z);
  _gfortran_transfer_complex (&T.0, 8);

-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/16303] [gfortran] Complex logarithm function sometimes chooses a non-principal branch
  2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
  2004-07-01  3:36 ` [Bug fortran/16303] " pinskia at gcc dot gnu dot org
@ 2004-07-03  8:46 ` jblomqvi at cc dot hut dot fi
  2004-07-03  8:55 ` jblomqvi at cc dot hut dot fi
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jblomqvi at cc dot hut dot fi @ 2004-07-03  8:46 UTC (permalink / raw)
  To: gcc-bugs


------- 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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/16303] [gfortran] Complex logarithm function sometimes chooses a non-principal branch
  2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
  2004-07-01  3:36 ` [Bug fortran/16303] " pinskia at gcc dot gnu dot org
  2004-07-03  8:46 ` jblomqvi at cc dot hut dot fi
@ 2004-07-03  8:55 ` jblomqvi at cc dot hut dot fi
  2004-07-11 12:43 ` [Bug fortran/16303] " giovannibajo at libero dot it
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jblomqvi at cc dot hut dot fi @ 2004-07-03  8:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jblomqvi at cc dot hut dot fi  2004-07-03 08:55 -------
Also, g95 and ifort handle the code above correctly.

-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/16303] Complex logarithm function sometimes chooses a non-principal branch
  2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
                   ` (2 preceding siblings ...)
  2004-07-03  8:55 ` jblomqvi at cc dot hut dot fi
@ 2004-07-11 12:43 ` giovannibajo at libero dot it
  2004-07-11 16:05 ` cvs-commit at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: giovannibajo at libero dot it @ 2004-07-11 12:43 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[gfortran] Complex logarithm|Complex logarithm function
                   |function sometimes chooses a|sometimes chooses a non-
                   |non-principal branch        |principal branch


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/16303] Complex logarithm function sometimes chooses a non-principal branch
  2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
                   ` (3 preceding siblings ...)
  2004-07-11 12:43 ` [Bug fortran/16303] " giovannibajo at libero dot it
@ 2004-07-11 16:05 ` cvs-commit at gcc dot gnu dot org
  2004-07-11 16:18 ` tobi at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-07-11 16:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-07-11 16:05 -------
Subject: Bug 16303

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pbrook@gcc.gnu.org	2004-07-11 16:05:08

Modified files:
	libgfortran    : ChangeLog 
	libgfortran/generated: exp_c4.c exp_c8.c 
	libgfortran/m4 : cexp.m4 

Log message:
	PR fortran/16303
	* m4/cexp.m4 (carg): Return -pi to pi.
	* generated/exp_c?.c: Regenerate.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.49&r2=1.50
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/exp_c4.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/exp_c8.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/m4/cexp.m4.diff?cvsroot=gcc&r1=1.2&r2=1.3



-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/16303] Complex logarithm function sometimes chooses a non-principal branch
  2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
                   ` (4 preceding siblings ...)
  2004-07-11 16:05 ` cvs-commit at gcc dot gnu dot org
@ 2004-07-11 16:18 ` tobi at gcc dot gnu dot org
  2004-07-11 19:02 ` jblomqvi at cc dot hut dot fi
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tobi at gcc dot gnu dot org @ 2004-07-11 16:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From tobi at gcc dot gnu dot org  2004-07-11 16:18 -------
hm, looks like an issue with the c library, instead. Paul Brook can't reproduce
it (debian linux), I can reproduce it (Fedora Core 2). What are you using?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/16303] Complex logarithm function sometimes chooses a non-principal branch
  2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
                   ` (5 preceding siblings ...)
  2004-07-11 16:18 ` tobi at gcc dot gnu dot org
@ 2004-07-11 19:02 ` jblomqvi at cc dot hut dot fi
  2004-07-11 19:30 ` tobi at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jblomqvi at cc dot hut dot fi @ 2004-07-11 19:02 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jblomqvi at cc dot hut dot fi  2004-07-11 19:02 -------
I'm running debian testing/i386 on an amd duron cpu, i.e. at the moment the c
library is version 2.3.2.ds1-13 and the system compiler is gcc 3.3.4-1.

I'm currently updating from gcc cvs, so I'll report back in a few hours when I
have compiled the thing and tried the example programs again.

-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/16303] Complex logarithm function sometimes chooses a non-principal branch
  2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
                   ` (6 preceding siblings ...)
  2004-07-11 19:02 ` jblomqvi at cc dot hut dot fi
@ 2004-07-11 19:30 ` tobi at gcc dot gnu dot org
  2004-07-11 20:59 ` jblomqvi at cc dot hut dot fi
  2004-07-12  4:14 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: tobi at gcc dot gnu dot org @ 2004-07-11 19:30 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From tobi at gcc dot gnu dot org  2004-07-11 19:30 -------
I don't think you have to recompile, the changed files shouldn't be used on
i686-pc-linux. A weird thing is that Paul has exactly the same glibc as you
have, and still he doesn't see the problem.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|0000-00-00 00:00:00         |2004-07-11 19:30:36
               date|                            |


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/16303] Complex logarithm function sometimes chooses a non-principal branch
  2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
                   ` (7 preceding siblings ...)
  2004-07-11 19:30 ` tobi at gcc dot gnu dot org
@ 2004-07-11 20:59 ` jblomqvi at cc dot hut dot fi
  2004-07-12  4:14 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jblomqvi at cc dot hut dot fi @ 2004-07-11 20:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jblomqvi at cc dot hut dot fi  2004-07-11 20:59 -------
Well, now I'm running gfortran 20040711, and lo and behold, the problems have
disappeared for me. Unfortunately I don't know if the reason is Paul's patch,
some update to the system as I do "apt-get dist-upgrade" fairly regularly, or
the phase of the moon. :(

-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/16303] Complex logarithm function sometimes chooses a non-principal branch
  2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
                   ` (8 preceding siblings ...)
  2004-07-11 20:59 ` jblomqvi at cc dot hut dot fi
@ 2004-07-12  4:14 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-12  4:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-07-12 04:14 -------
Closing as works for me.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |WORKSFORME


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-07-12  4:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-30 19:57 [Bug fortran/16303] New: [gfortran] Complex logarithm function sometimes chooses a non-principal branch jblomqvi at cc dot hut dot fi
2004-07-01  3:36 ` [Bug fortran/16303] " pinskia at gcc dot gnu dot org
2004-07-03  8:46 ` jblomqvi at cc dot hut dot fi
2004-07-03  8:55 ` jblomqvi at cc dot hut dot fi
2004-07-11 12:43 ` [Bug fortran/16303] " giovannibajo at libero dot it
2004-07-11 16:05 ` cvs-commit at gcc dot gnu dot org
2004-07-11 16:18 ` tobi at gcc dot gnu dot org
2004-07-11 19:02 ` jblomqvi at cc dot hut dot fi
2004-07-11 19:30 ` tobi at gcc dot gnu dot org
2004-07-11 20:59 ` jblomqvi at cc dot hut dot fi
2004-07-12  4:14 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).