8000 BUG: npy_acosh fallback too simple. · ewmoore/numpy@3af3753 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3af3753

Browse files
committed
BUG: npy_acosh fallback too simple.
Fixes numpygh-6712.
1 parent 8a76291 commit 3af3753

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

numpy/core/src/npymath/npy_math.c.src

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,20 @@ double npy_hypot(double x, double y)
221221
#ifndef HAVE_ACOSH
222222
double npy_acosh(double x)
223223
{
224-
return 2*npy_log(npy_sqrt((x + 1.0)/2) + npy_sqrt((x - 1.0)/2));
224+
if (x < 1.0) {
225+
return NPY_NAN;
226+
}
227+
228+
if (npy_isfinite(x)) {
229+
if (x > 1e8) {
230+
return npy_log(x) + NPY_LOGE2;
231+
}
232+
else {
233+
double u = x - 1.0;
234+
return npy_log1p(u + npy_sqrt(2*u + u*u));
235+
}
236+
}
237+
return x;
225238
}
226239
#endif
227240

0 commit comments

Comments
 (0)
0