From 3af3753f8f518c8ea542511f8a117508b12e2802 Mon Sep 17 00:00:00 2001 From: Eric Moore Date: Fri, 8 Jan 2016 17:31:07 -0500 Subject: [PATCH] BUG: npy_acosh fallback too simple. Fixes gh-6712. --- numpy/core/src/npymath/npy_math.c.src | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/numpy/core/src/npymath/npy_math.c.src b/numpy/core/src/npymath/npy_math.c.src index 32fa41788e0b..4dcb01986d7b 100644 --- a/numpy/core/src/npymath/npy_math.c.src +++ b/numpy/core/src/npymath/npy_math.c.src @@ -221,7 +221,20 @@ double npy_hypot(double x, double y) #ifndef HAVE_ACOSH double npy_acosh(double x) { - return 2*npy_log(npy_sqrt((x + 1.0)/2) + npy_sqrt((x - 1.0)/2)); + if (x < 1.0) { + return NPY_NAN; + } + + if (npy_isfinite(x)) { + if (x > 1e8) { + return npy_log(x) + NPY_LOGE2; + } + else { + double u = x - 1.0; + return npy_log1p(u + npy_sqrt(2*u + u*u)); + } + } + return x; } #endif