aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2012-08-18 12:24:30 +0100
committerMark Dickinson <mdickinson@enthought.com>2012-08-18 12:24:30 +0100
commit05d79e9abfac38878298e4381c9166e58488664a (patch)
treebf5cab95e59ccc598eb7b9c3707efa65fd0040f2 /Modules/_math.c
parenttutorial typo fix (diff)
downloadcpython-05d79e9abfac38878298e4381c9166e58488664a.tar.gz
cpython-05d79e9abfac38878298e4381c9166e58488664a.tar.bz2
cpython-05d79e9abfac38878298e4381c9166e58488664a.zip
Issue #15477: Add workaround for log1p(-0.0) on platforms where it's broken.
Diffstat (limited to 'Modules/_math.c')
-rw-r--r--Modules/_math.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/Modules/_math.c b/Modules/_math.c
index 2fef48107f1..fe75a36ec51 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 */