[BZ #1466]
authorUlrich Drepper <drepper@redhat.com>
Thu, 13 Oct 2005 19:08:37 +0000 (19:08 +0000)
committerUlrich Drepper <drepper@redhat.com>
Thu, 13 Oct 2005 19:08:37 +0000 (19:08 +0000)
* sysdeps/generic/s_csqrt.c (__csqrt): For zero real part, return
principal square root.
* sysdeps/generic/s_csqrtf.c (__csqrtf): Likewise.
* sysdeps/generic/s_csqrtl.c (__csqrtl): Likewise.
* math/libm-test.inc (csqrt_test): Add test for returning
principal value.

ChangeLog
math/libm-test.inc
sysdeps/generic/s_csqrt.c
sysdeps/generic/s_csqrtf.c
sysdeps/generic/s_csqrtl.c

index dc1aca6..6bca4c8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2005-10-13  Ulrich Drepper  <drepper@redhat.com>
 
+       [BZ #1466]
+       * sysdeps/generic/s_csqrt.c (__csqrt): For zero real part, return
+       principal square root.
+       * sysdeps/generic/s_csqrtf.c (__csqrtf): Likewise.
+       * sysdeps/generic/s_csqrtl.c (__csqrtl): Likewise.
+       * math/libm-test.inc (csqrt_test): Add test for returning
+       principal value.
+
        * include/features.h: Define _POSIX_C_SOURCE to 200112 for
        _XOPEN_SOURCE == 600.
 
index be05222..1550901 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997-2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Andreas Jaeger <aj@suse.de>, 1997.
 
 #define M_PI2_LOG10El          M_PI_2l * M_LOG10El
 #define M_PI4_LOG10El          M_PI_4l * M_LOG10El
 #define M_PI_LOG10El           M_PIl * M_LOG10El
+#define M_SQRT_2_2             0.70710678118654752440084436210484903L /* sqrt (2) / 2 */
 
 static FILE *ulps_file;        /* File to document difference.  */
 static int output_ulps;        /* Should ulps printed?  */
@@ -2212,6 +2213,9 @@ csqrt_test (void)
   TEST_c_c (csqrt, 0.75L, 1.25L, 1.05065169626078392338656675760808326L, 0.594868882070379067881984030639932657L);
   TEST_c_c (csqrt, -2, -3, 0.89597747612983812471573375529004348L, -1.6741492280355400404480393008490519L);
   TEST_c_c (csqrt, -2, 3, 0.89597747612983812471573375529004348L, 1.6741492280355400404480393008490519L);
+  /* Principal square root should be returned (i.e., non-negative real
+     part).  */
+  TEST_c_c (csqrt, 0, -1, M_SQRT_2_2, -M_SQRT_2_2);
 
   END (csqrt, complex);
 }
index 0bb6690..04ed410 100644 (file)
@@ -1,5 +1,5 @@
 /* Complex square root of double value.
-   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Based on an algorithm by Stephen L. Moshier <moshier@world.std.com>.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
@@ -79,8 +79,8 @@ __csqrt (__complex__ double x)
        {
          double r = __ieee754_sqrt (0.5 * fabs (__imag__ x));
 
-         __real__ res = __copysign (r, __imag__ x);
-         __imag__ res = r;
+         __real__ res = r;
+         __imag__ res = __copysign (r, __imag__ x);
        }
       else
        {
index b02c605..2fba69c 100644 (file)
@@ -1,5 +1,5 @@
 /* Complex square root of float value.
-   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Based on an algorithm by Stephen L. Moshier <moshier@world.std.com>.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
@@ -79,8 +79,8 @@ __csqrtf (__complex__ float x)
        {
          float r = __ieee754_sqrtf (0.5 * fabsf (__imag__ x));
 
-         __real__ res = __copysignf (r, __imag__ x);
-         __imag__ res = r;
+         __real__ res = r;
+         __imag__ res = __copysignf (r, __imag__ x);
        }
       else
        {
index 8e27750..9d00946 100644 (file)
@@ -1,5 +1,5 @@
 /* Complex square root of long double value.
-   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Based on an algorithm by Stephen L. Moshier <moshier@world.std.com>.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
@@ -79,8 +79,8 @@ __csqrtl (__complex__ long double x)
        {
          long double r = __ieee754_sqrtl (0.5 * fabsl (__imag__ x));
 
-         __real__ res = __copysignl (r, __imag__ x);
-         __imag__ res = r;
+         __real__ res = r;
+         __imag__ res = __copysignl (r, __imag__ x);
        }
       else
        {