summaryrefslogtreecommitdiff
path: root/lib/libm/complex
diff options
context:
space:
mode:
authormaya <maya@NetBSD.org>2017-01-01 19:32:14 +0000
committermaya <maya@NetBSD.org>2017-01-01 19:32:14 +0000
commitbf3b7e6da216c731791628fa72ea18327ddd807a (patch)
tree82f8c38cb9a315dbb5c9e5ef78e64a211cd643fd /lib/libm/complex
parentf6d275930522375b604b91317787a69a3691bf5e (diff)
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 (limited to 'lib/libm/complex')
-rw-r--r--lib/libm/complex/csqrt.c13
-rw-r--r--lib/libm/complex/csqrtf.c13
2 files changed, 16 insertions, 10 deletions
diff --git a/lib/libm/complex/csqrt.c b/lib/libm/complex/csqrt.c
index 2b1849b5f08..51d640c56b3 100644
--- a/lib/libm/complex/csqrt.c
+++ b/lib/libm/complex/csqrt.c
@@ -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;
}
diff --git a/lib/libm/complex/csqrtf.c b/lib/libm/complex/csqrtf.c
index 8deb0525c82..8f66a8444fc 100644
--- a/lib/libm/complex/csqrtf.c
+++ b/lib/libm/complex/csqrtf.c
@@ -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;
}