diff options
author | David Cournapeau <cournape@gmail.com> | 2009-07-20 05:36:30 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2009-07-20 05:36:30 +0000 |
commit | c747e8026dfa067de93d244db8b10f20594bb25c (patch) | |
tree | b8b5a29658cc70918759eb6bf3bc726668e0b788 /numpy | |
parent | 197d9411d78b405fa9fc9de90c29660af833185c (diff) | |
download | numpy-c747e8026dfa067de93d244db8b10f20594bb25c.tar.gz |
Handle nan entries for hypot.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/npymath/npy_math.c.src | 12 |
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); |