Module Name: src Committed By: maya Date: Sun Jan 1 19:32:14 UTC 2017
Modified Files: src/lib/libm/complex: csqrt.c csqrtf.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/lib/libm/complex/csqrt.c \ src/lib/libm/complex/csqrtf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libm/complex/csqrt.c diff -u src/lib/libm/complex/csqrt.c:1.3 src/lib/libm/complex/csqrt.c:1.4 --- src/lib/libm/complex/csqrt.c:1.3 Sat Dec 31 20:01:15 2016 +++ src/lib/libm/complex/csqrt.c Sun Jan 1 19:32:14 2017 @@ -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 @@ csqrt(double complex z) 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 @@ csqrt(double complex z) t = scale * fabs((0.5 * y) / r); r *= scale; } - if (signbit(y)) - w = t - r * I; - else + if (y > 0) w = t + r * I; + else + w = t - r * I; return w; } Index: src/lib/libm/complex/csqrtf.c diff -u src/lib/libm/complex/csqrtf.c:1.3 src/lib/libm/complex/csqrtf.c:1.4 --- src/lib/libm/complex/csqrtf.c:1.3 Sat Dec 31 22:54:56 2016 +++ src/lib/libm/complex/csqrtf.c Sun Jan 1 19:32:14 2017 @@ -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 @@ csqrtf(float complex z) 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 @@ csqrtf(float complex z) r *= scale; } - if (signbit(y)) - w = t - r * I; - else + if (y > 0) w = t + r * I; + else + w = t - r * I; return w; }