Revert "Update to FreeBSD libm r336523."
This reverts commit f86ee10278116d211cfb08679416444e0e714cb5.
Incorrect result for fmodf(3.0f, 0f) = 1.0f breaks ART tests.
Bug: 111710419
Test: art/test/testrunner/testrunner.py -b -t 436-rem-float --target
Change-Id: I7eae68fb92740db33415d16418447bcbbd98ecba
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c b/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c
index 16d3266..195e3b7 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c
@@ -27,21 +27,27 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/s_csqrtf.c 336412 2018-07-17 12:01:59Z bde $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_csqrtf.c 326219 2017-11-26 02:00:33Z pfg $");
#include <complex.h>
#include <math.h>
#include "math_private.h"
+/*
+ * gcc doesn't implement complex multiplication or division correctly,
+ * so we need to handle infinities specially. We turn on this pragma to
+ * notify conforming c99 compilers that the fast-but-incorrect code that
+ * gcc generates is acceptable, since the special cases have already been
+ * handled.
+ */
+#pragma STDC CX_LIMITED_RANGE ON
+
float complex
csqrtf(float complex z)
{
+ float a = crealf(z), b = cimagf(z);
double t;
- float a, b;
-
- a = creal(z);
- b = cimag(z);
/* Handle special cases. */
if (z == 0)
@@ -50,7 +56,7 @@
return (CMPLXF(INFINITY, b));
if (isnan(a)) {
t = (b - b) / (b - b); /* raise invalid if b is not a NaN */
- return (CMPLXF(a + 0.0L + t, a + 0.0L + t)); /* NaN + NaN i */
+ return (CMPLXF(a, t)); /* return NaN + NaN i */
}
if (isinf(a)) {
/*
@@ -64,10 +70,10 @@
else
return (CMPLXF(a, copysignf(b - b, b)));
}
- if (isnan(b)) {
- t = (a - a) / (a - a); /* raise invalid */
- return (CMPLXF(b + 0.0L + t, b + 0.0L + t)); /* NaN + NaN i */
- }
+ /*
+ * The remaining special case (b is NaN) is handled just fine by
+ * the normal code path below.
+ */
/*
* We compute t in double precision to avoid overflow and to
@@ -76,9 +82,9 @@
*/
if (a >= 0) {
t = sqrt((a + hypot(a, b)) * 0.5);
- return (CMPLXF(t, b / (2 * t)));
+ return (CMPLXF(t, b / (2.0 * t)));
} else {
t = sqrt((-a + hypot(a, b)) * 0.5);
- return (CMPLXF(fabsf(b) / (2 * t), copysignf(t, b)));
+ return (CMPLXF(fabsf(b) / (2.0 * t), copysignf(t, b)));
}
}