[PATCH] libgfortran/24313 wrong branch cut for csqrt()

Steve Kargl sgk@troutmask.apl.washington.edu
Tue Oct 11 20:43:00 GMT 2005


The attached patch fixes a problem with chosing the
proper branch cut for csqrt((0,-1)).  This problem 
is also in glibc in that libgfortran imported glibc's
csqrt{f}, which is used on OS's without these functions
in libm.

Bubblestrap and regresion tested on amd64-*-freebsd.

2005-10-11  Steven G. Kargl  <kargls@comcast.net>

	PR libgfortran/24313
	*  c99_functions.c (csqrtf, csqrt): Fix choice of branch cut.

	gfortran.dg/csqrt_2.f:  New test.

-- 
Steve
-------------- next part --------------
c { dg-do run }
c Fix PR libgfortran/24313
      complex x, y
      complex z
      z = cmplx(0.707106, -0.707106)
      x = cmplx(0.0,-1.0)
      y = sqrt(x)
      if (abs(y - z) / abs(z) > 1.e-4) call abort

      x = cmplx(tiny(1.),-1.0)
      y = sqrt(x)
      if (abs(y - z) / abs(z) > 1.e-4) call abort

      x = cmplx(-tiny(1.),-1.0)
      y = sqrt(x)
      if (abs(y - z) / abs(z) > 1.e-4) call abort

      end

-------------- next part --------------
Index: c99_functions.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/intrinsics/c99_functions.c,v
retrieving revision 1.16
diff -c -p -r1.16 c99_functions.c
*** c99_functions.c	27 Sep 2005 21:12:52 -0000	1.16
--- c99_functions.c	11 Oct 2005 20:14:32 -0000
*************** csqrtf (float complex z)
*** 669,675 ****
  
        r = sqrtf (0.5 * fabsf (im));
  
!       COMPLEX_ASSIGN (v, copysignf (r, im), r);
      }
    else
      {
--- 669,675 ----
  
        r = sqrtf (0.5 * fabsf (im));
  
!       COMPLEX_ASSIGN (v, r, copysignf (r, im));
      }
    else
      {
*************** csqrt (double complex z)
*** 722,728 ****
  
        r = sqrt (0.5 * fabs (im));
  
!       COMPLEX_ASSIGN (v, copysign (r, im), r);
      }
    else
      {
--- 722,728 ----
  
        r = sqrt (0.5 * fabs (im));
  
!       COMPLEX_ASSIGN (v, r, copysign (r, im));
      }
    else
      {


More information about the Fortran mailing list