diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2012-08-18 11:26:15 (GMT) |
---|---|---|
committer | Mark Dickinson <mdickinson@enthought.com> | 2012-08-18 11:26:15 (GMT) |
commit | 35fa864840c7ab56acc474b6c035fdc6ae9005a3 (patch) | |
tree | 01f11ea091941088ffacbcc9021d3f6938b3d686 /Modules | |
parent | 8c601b0b850a32c49cf3a939f3641c3d67269d8e (diff) | |
parent | 05d79e9abfac38878298e4381c9166e58488664a (diff) | |
download | cpython-35fa864840c7ab56acc474b6c035fdc6ae9005a3.zip cpython-35fa864840c7ab56acc474b6c035fdc6ae9005a3.tar.gz cpython-35fa864840c7ab56acc474b6c035fdc6ae9005a3.tar.bz2 |
Issue #15477: Merge fix from 3.2
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_math.c | 23 | ||||
-rw-r--r-- | Modules/_math.h | 8 |
2 files changed, 25 insertions, 6 deletions
diff --git a/Modules/_math.c b/Modules/_math.c index 2fef481..fe75a36 100644 --- a/Modules/_math.c +++ b/Modules/_math.c @@ -189,6 +189,27 @@ _Py_expm1(double x) significant loss of precision that arises from direct evaluation when x is small. */ +#ifdef HAVE_LOG1P + +double +_Py_log1p(double x) +{ + /* Some platforms supply a log1p function but don't respect the sign of + zero: log1p(-0.0) gives 0.0 instead of the correct result of -0.0. + + To save fiddling with configure tests and platform checks, we handle the + special case of zero input directly on all platforms. + */ + if (x == 0.0) { + return x; + } + else { + return log1p(x); + } +} + +#else + double _Py_log1p(double x) { @@ -230,3 +251,5 @@ _Py_log1p(double x) return log(1.+x); } } + +#endif /* ifdef HAVE_LOG1P */ diff --git a/Modules/_math.h b/Modules/_math.h index c0ceece..cf079ad 100644 --- a/Modules/_math.h +++ b/Modules/_math.h @@ -36,10 +36,6 @@ double _Py_log1p(double x); #define m_expm1 _Py_expm1 #endif -#ifdef HAVE_LOG1P -#define m_log1p log1p -#else -/* if the system doesn't have log1p, use the substitute - function defined in Modules/_math.c. */ +/* Use the substitute from _math.c on all platforms: + it includes workarounds for buggy handling of zeros. */ #define m_log1p _Py_log1p -#endif |