Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libm/complex compare to zero, instead of using signbit, ...



details:   https://anonhg.NetBSD.org/src/rev/ccb1111122ef
branches:  trunk
changeset: 820148:ccb1111122ef
user:      maya <maya%NetBSD.org@localhost>
date:      Sun Jan 01 19:32:14 2017 +0000

description:
compare to zero, instead of using signbit, and be more specific in comment.
-0.0 > 0 is also false. no functional change.

while this is mostly a change to be consistent in style (the rest of the
comparisons aren't done with signbit), it is also a micro-optimization.

with our default compile flags, calls to copysign are libm calls (and a
whole function call!!). this generates more efficient code.

diffstat:

 lib/libm/complex/csqrt.c  |  13 ++++++++-----
 lib/libm/complex/csqrtf.c |  13 ++++++++-----
 2 files changed, 16 insertions(+), 10 deletions(-)

diffs (68 lines):

diff -r 01670f53b690 -r ccb1111122ef lib/libm/complex/csqrt.c
--- a/lib/libm/complex/csqrt.c  Sun Jan 01 12:39:33 2017 +0000
+++ b/lib/libm/complex/csqrt.c  Sun Jan 01 19:32:14 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: csqrt.c,v 1.3 2016/12/31 20:01:15 maya Exp $ */
+/* $NetBSD: csqrt.c,v 1.4 2017/01/01 19:32:14 maya Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -41,7 +41,10 @@
        x = creal (z);
        y = cimag (z);
 
-       /* Input is a real number that isn't on the branch cut */
+       /* 
+        * input is a real number and imaginary part isn't -0.0.
+        * negative zero is on the branch cut.
+        */
        if ((y == 0.0) && !signbit(y)) {
                if (x == 0.0) {
                        w = 0.0 + y * I;
@@ -93,9 +96,9 @@
                t = scale * fabs((0.5 * y) / r);
                r *= scale;
        }
-       if (signbit(y))
+       if (y > 0)
+               w = t + r * I;
+       else
                w = t - r * I;
-       else
-               w = t + r * I;
        return w;
 }
diff -r 01670f53b690 -r ccb1111122ef lib/libm/complex/csqrtf.c
--- a/lib/libm/complex/csqrtf.c Sun Jan 01 12:39:33 2017 +0000
+++ b/lib/libm/complex/csqrtf.c Sun Jan 01 19:32:14 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: csqrtf.c,v 1.3 2016/12/31 22:54:56 maya Exp $ */
+/* $NetBSD: csqrtf.c,v 1.4 2017/01/01 19:32:14 maya Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -41,7 +41,10 @@
        x = crealf (z);
        y = cimagf (z);
 
-       /* Input is a real number that isn't on the branch cut */
+       /* 
+        * input is a real number and imaginary part isn't -0.0.
+        * negative zero is on the branch cut.
+        */
        if ((y == 0.0f) && !signbit(y)) {
                if (x < 0.0f) {
                        w = 0.0f + sqrtf(-x) * I;
@@ -93,9 +96,9 @@
                r *= scale;
        }
 
-       if (signbit(y))
+       if (y > 0)
+               w = t + r * I;
+       else
                w = t - r * I;
-       else
-               w = t + r * I;
        return w;
 }



Home | Main Index | Thread Index | Old Index