This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[gfortran] patch for PR 14396 - Intrinsic SQRT and CSQRT givewrong answer with COMPLEX argument.
- From: Bud Davis <bdavis9659 at comcast dot net>
- To: gfortran <fortran at gcc dot gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Sat, 06 Mar 2004 13:36:48 -0600
- Subject: [gfortran] patch for PR 14396 - Intrinsic SQRT and CSQRT givewrong answer with COMPLEX argument.
sqrt and csqrt are using a local instead of the passed in parameter.
note that if you do not use the gfortran version of these routines you
will not see the problem.
Here is the bugzilla link with some info on which platforms can
duplicate it and which cannot.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14396
No additional testsuite regressions. Tested i686/gnu/linux.
Here is a test case that fails before and passes after the patch is installed:
C PR 14396
C extracted from intrinsic77.f in the g77 testsuite
logical fail
common /flags/ fail
fail = .false.
call square_root
if (fail) call abort
end
subroutine square_root
intrinsic sqrt, dsqrt, csqrt
real x, a
x = 4.0
a = 2.0
call c_r(SQRT(x),a,'SQRT(real)')
call c_d(SQRT(1.d0*x),1.d0*a,'SQRT(double)')
call c_c(SQRT((1.,0.)*x),(1.,0.)*a,'SQRT(complex)')
call c_d(DSQRT(1.d0*x),1.d0*a,'DSQRT(double)')
call c_c(CSQRT((1.,0.)*x),(1.,0.)*a,'CSQRT(complex)')
call p_r_r(SQRT,x,a,'SQRT')
call p_d_d(DSQRT,1.d0*x,1.d0*a,'DSQRT')
call p_c_c(CSQRT,(1.,0.)*x,(1.,0.)*a ,'CSQRT')
end
subroutine failure(label)
c Report failure and set flag
character*(*) label
logical fail
common /flags/ fail
write(6,'(a,a,a)') 'Test ',label,' FAILED'
fail = .true.
end
subroutine c_r(a,b,label)
c Check if REAL a equals b, and fail otherwise
real a, b
character*(*) label
if ( abs(a-b) .gt. 1.0e-5 ) then
call failure(label)
write(6,*) 'Got ',a,' expected ', b
end if
end
subroutine c_d(a,b,label)
c Check if DOUBLE PRECISION a equals b, and fail otherwise
double precision a, b
character*(*) label
if ( abs(a-b) .gt. 1.0d-5 ) then
call failure(label)
write(6,*) 'Got ',a,' expected ', b
end if
end
subroutine c_c(a,b,label)
c Check if COMPLEX a equals b, and fail otherwise
complex a, b
character*(*) label
if ( abs(a-b) .gt. 1.0e-5 ) then
call failure(label)
write(6,*) 'Got ',a,' expected ', b
end if
end
subroutine p_r_r(f,x,a,label)
c Check if REAL f(x) equals a for REAL x
real f,x,a
character*(*) label
call c_r(f(x),a,label)
end
subroutine p_d_d(f,x,a,label)
c Check if DOUBLE PRECISION f(x) equals a for DOUBLE PRECISION x
double precision f,x,a
character*(*) label
call c_d(f(x),a,label)
end
subroutine p_c_c(f,x,a,label)
c Check if COMPLEX f(x) equals a for COMPLEX x
complex f,x,a
character*(*) label
call c_c(f(x),a,label)
end
2004-03-06 Bud Davis <bdavis9659@comcast.net>
PR 14396
* generated/exp_c4.c(csqrtf)
* generated/exp_c8.c(csqrt): Use parameter as input.
regards,
bud
Index: gcc/libgfortran/generated/exp_c4.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/generated/Attic/exp_c4.c,v
retrieving revision 1.1.2.3
diff -c -3 -p -r1.1.2.3 exp_c4.c
*** gcc/libgfortran/generated/exp_c4.c 19 Sep 2003 19:11:11 -0000 1.1.2.3
--- gcc/libgfortran/generated/exp_c4.c 6 Mar 2004 15:37:15 -0000
*************** csqrtf (GFC_COMPLEX_4 z)
*** 92,99 ****
GFC_REAL_4 im;
GFC_COMPLEX_4 v;
! re = REALPART (re);
! im = IMAGPART (im);
if (im == 0.0)
{
if (re < 0.0)
--- 92,99 ----
GFC_REAL_4 im;
GFC_COMPLEX_4 v;
! re = REALPART (z);
! im = IMAGPART (z);
if (im == 0.0)
{
if (re < 0.0)
Index: gcc/libgfortran/generated/exp_c8.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/generated/Attic/exp_c8.c,v
retrieving revision 1.1.2.3
diff -c -3 -p -r1.1.2.3 exp_c8.c
*** gcc/libgfortran/generated/exp_c8.c 19 Sep 2003 19:11:11 -0000 1.1.2.3
--- gcc/libgfortran/generated/exp_c8.c 6 Mar 2004 15:37:15 -0000
*************** csqrt (GFC_COMPLEX_8 z)
*** 92,99 ****
GFC_REAL_8 im;
GFC_COMPLEX_8 v;
! re = REALPART (re);
! im = IMAGPART (im);
if (im == 0.0)
{
if (re < 0.0)
--- 92,99 ----
GFC_REAL_8 im;
GFC_COMPLEX_8 v;
! re = REALPART (z);
! im = IMAGPART (z);
if (im == 0.0)
{
if (re < 0.0)