summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorEric Moore <ewm@redtetrahedron.org>2013-10-29 18:40:30 -0400
committerEric Moore <ewm@redtetrahedron.org>2013-10-29 18:40:30 -0400
commit753d611615d4d98c37a207940c8648dc15329f66 (patch)
tree5ae757d649656be82f0608dc2dc2f3544fb76c0d /numpy/core
parent54d3559c325be26f8fee71e1c669cc502286dc77 (diff)
downloadnumpy-753d611615d4d98c37a207940c8648dc15329f66.tar.gz
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
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/npymath/npy_math.c.src13
-rw-r--r--numpy/core/tests/test_umath.py5
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):