summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/npymath/npy_math.c.src12
1 files changed, 11 insertions, 1 deletions
diff --git a/numpy/core/src/npymath/npy_math.c.src b/numpy/core/src/npymath/npy_math.c.src
index fbe38bb48..4af5a8859 100644
--- a/numpy/core/src/npymath/npy_math.c.src
+++ b/numpy/core/src/npymath/npy_math.c.src
@@ -98,6 +98,15 @@ 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;
+ }
+ }
+
x = npy_fabs(x);
y = npy_fabs(y);
if (x < y) {
@@ -105,8 +114,9 @@ double npy_hypot(double x, double y)
x = y;
y = temp;
}
- if (x == 0.)
+ if (x == 0.) {
return 0.;
+ }
else {
yx = y/x;
return x*npy_sqrt(1.+yx*yx);