From 753d611615d4d98c37a207940c8648dc15329f66 Mon Sep 17 00:00:00 2001 From: Eric Moore Date: Tue, 29 Oct 2013 18:40:30 -0400 Subject: BUG: fix handling of infs in hypot on windows On any platform where we used our own implementation of hypot, (e.g. windows) there were several issues with infs. hypot(inf, y) == inf, for all y including nan. We now check for inf and handle this case explicitly for all y instead of just y = nan. Although hypot(inf, 0) was correctly returning inf, it was incorrectly raising the invalid floating point exception. Fixes gh-2385 --- numpy/core/src/npymath/npy_math.c.src | 13 ++++++------- numpy/core/tests/test_umath.py | 5 +++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/numpy/core/src/npymath/npy_math.c.src b/numpy/core/src/npymath/npy_math.c.src index 6f6f2242e..61f1d79ab 100644 --- a/numpy/core/src/npymath/npy_math.c.src +++ b/numpy/core/src/npymath/npy_math.c.src @@ -183,13 +183,12 @@ double npy_hypot(double x, double y) { double yx; - /* Handle the case where x or y is a NaN */ - if (npy_isnan(x * y)) { - if (npy_isinf(x) || npy_isinf(y)) { - return NPY_INFINITY; - } else { - return NPY_NAN; - } + if (npy_isinf(x) || npy_isinf(y)) { + return NPY_INFINITY; + } + + if (npy_isnan(x) || npy_isnan(y)) { + return NPY_NAN; } x = npy_fabs(x); diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index 56e7311e2..d61b516ac 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -340,6 +340,11 @@ class TestHypotSpecialValues(TestCase): assert_hypot_isinf(np.inf, np.nan) assert_hypot_isinf(np.inf, 0) assert_hypot_isinf(0, np.inf) + assert_hypot_isinf(np.inf, np.inf) + assert_hypot_isinf(np.inf, 23.0) + + def test_no_fpe(self): + assert_no_warnings(ncu.hypot, np.inf, 0) def assert_arctan2_isnan(x, y): -- cgit v1.2.1