diff options
| author | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-03-02 02:55:30 +0100 |
|---|---|---|
| committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-03-02 03:07:09 +0100 |
| commit | 18cda3b66cfb50396c419cd66ae86e2828d03b32 (patch) | |
| tree | 6677256429316b1d69793fd6e133d0103d7b7ace /numpy/core/src/npymath | |
| parent | 0dbd06f95d37e42bea3708954e539db70592e7ea (diff) | |
| download | numpy-18cda3b66cfb50396c419cd66ae86e2828d03b32.tar.gz | |
BUG: fix non-c99 fallback for np.inf input to log1p/expm1
closes gh-4225
Diffstat (limited to 'numpy/core/src/npymath')
| -rw-r--r-- | numpy/core/src/npymath/npy_math.c.src | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/numpy/core/src/npymath/npy_math.c.src b/numpy/core/src/npymath/npy_math.c.src index 61f1d79ab..1ca7033af 100644 --- a/numpy/core/src/npymath/npy_math.c.src +++ b/numpy/core/src/npymath/npy_math.c.src @@ -65,14 +65,19 @@ #ifndef HAVE_EXPM1 double npy_expm1(double x) { - const double u = npy_exp(x); - - if (u == 1.0) { + if (npy_isinf(x) && x > 0) { return x; - } else if (u - 1.0 == -1.0) { - return -1; - } else { - return (u - 1.0) * x/npy_log(u); + } + else { + const double u = npy_exp(x); + + if (u == 1.0) { + return x; + } else if (u - 1.0 == -1.0) { + return -1; + } else { + return (u - 1.0) * x/npy_log(u); + } } } #endif @@ -80,13 +85,18 @@ double npy_expm1(double x) #ifndef HAVE_LOG1P double npy_log1p(double x) { - const double u = 1. + x; - const double d = u - 1.; - - if (d == 0) { + if (npy_isinf(x) && x > 0) { return x; - } else { - return npy_log(u) * x / d; + } + else { + const double u = 1. + x; + const double d = u - 1.; + + if (d == 0) { + return x; + } else { + return npy_log(u) * x / d; + } } } #endif |
