Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e675f08

Browse files
committed
Merged revisions 67707 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r67707 | mark.dickinson | 2008-12-11 19:28:08 +0000 (Thu, 11 Dec 2008) | 5 lines Issues #3167, #3682: tests for math.log and math.log10 were failing on Solaris and OpenBSD. Fix this by handling special values and domain errors directly in mathmodule.c, passing only positive nonspecial floats to the system log/log10. ........
1 parent da2706b commit e675f08

2 files changed

Lines changed: 60 additions & 3 deletions

File tree

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ Library
8787
support unusual filenames (such as those containing semi-colons) in
8888
Content-Disposition headers.
8989

90+
Extension Modules
91+
-----------------
92+
93+
- Issues #3167, #3682: Fix test_math failures for log, log10 on Solaris,
94+
OpenBSD.
9095

9196
Build
9297
-----

Modules/mathmodule.c

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,58 @@ m_atan2(double y, double x)
136136
return atan2(y, x);
137137
}
138138

139+
/*
140+
Various platforms (Solaris, OpenBSD) do nonstandard things for log(0),
141+
log(-ve), log(NaN). Here are wrappers for log and log10 that deal with
142+
special values directly, passing positive non-special values through to
143+
the system log/log10.
144+
*/
145+
146+
static double
147+
m_log(double x)
148+
{
149+
if (Py_IS_FINITE(x)) {
150+
if (x > 0.0)
151+
return log(x);
152+
errno = EDOM;
153+
if (x == 0.0)
154+
return -Py_HUGE_VAL; /* log(0) = -inf */
155+
else
156+
return Py_NAN; /* log(-ve) = nan */
157+
}
158+
else if (Py_IS_NAN(x))
159+
return x; /* log(nan) = nan */
160+
else if (x > 0.0)
161+
return x; /* log(inf) = inf */
162+
else {
163+
errno = EDOM;
164+
return Py_NAN; /* log(-inf) = nan */
165+
}
166+
}
167+
168+
static double
169+
m_log10(double x)
170+
{
171+
if (Py_IS_FINITE(x)) {
172+
if (x > 0.0)
173+
return log10(x);
174+
errno = EDOM;
175+
if (x == 0.0)
176+
return -Py_HUGE_VAL; /* log10(0) = -inf */
177+
else
178+
return Py_NAN; /* log10(-ve) = nan */
179+
}
180+
else if (Py_IS_NAN(x))
181+
return x; /* log10(nan) = nan */
182+
else if (x > 0.0)
183+
return x; /* log10(inf) = inf */
184+
else {
185+
errno = EDOM;
186+
return Py_NAN; /* log10(-inf) = nan */
187+
}
188+
}
189+
190+
139191
/*
140192
math_1 is used to wrap a libm function f that takes a double
141193
arguments and returns a double.
@@ -831,11 +883,11 @@ math_log(PyObject *self, PyObject *args)
831883
if (!PyArg_UnpackTuple(args, "log", 1, 2, &arg, &base))
832884
return NULL;
833885

834-
num = loghelper(arg, log, "log");
886+
num = loghelper(arg, m_log, "log");
835887
if (num == NULL || base == NULL)
836888
return num;
837889

838-
den = loghelper(base, log, "log");
890+
den = loghelper(base, m_log, "log");
839891
if (den == NULL) {
840892
Py_DECREF(num);
841893
return NULL;
@@ -854,7 +906,7 @@ If the base not specified, returns the natural logarithm (base e) of x.");
854906
static PyObject *
855907
math_log10(PyObject *self, PyObject *arg)
856908
{
857-
return loghelper(arg, log10, "log10");
909+
return loghelper(arg, m_log10, "log10");
858910
}
859911

860912
PyDoc_STRVAR(math_log10_doc,

0 commit comments

Comments
 (0)