Skip to content

Commit 5282f4f

Browse files
committed
gh-89381: Fix invalid signatures of math/cmath.log
1 parent 8e9d08b commit 5282f4f

File tree

8 files changed

+44
-49
lines changed

8 files changed

+44
-49
lines changed

Doc/library/cmath.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ Power and logarithmic functions
8989
logarithms.
9090

9191

92-
.. function:: log(x[, base])
92+
.. function:: log(x, base=None)
9393

9494
Returns the logarithm of *x* to the given *base*. If the *base* is not
95-
specified, returns the natural logarithm of *x*. There is one branch cut, from 0
96-
along the negative real axis to -∞, continuous from above.
95+
specified or is None, returns the natural logarithm of *x*. There is one
96+
branch cut, from 0 along the negative real axis to -∞, continuous from above.
9797

9898

9999
.. function:: log10(x)

Doc/library/math.rst

+4-5
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,12 @@ Power and logarithmic functions
393393
.. versionadded:: 3.2
394394

395395

396-
.. function:: log(x[, base])
396+
.. function:: log(x, base=None)
397397

398-
With one argument, return the natural logarithm of *x* (to base *e*).
399-
400-
With two arguments, return the logarithm of *x* to the given *base*,
401-
calculated as ``log(x)/log(base)``.
398+
Return the logarithm of *x* to the given *base*.
402399

400+
If the *base* is not specified or is None, returns the natural
401+
logarithm (base *e*) of *x*.
403402

404403
.. function:: log1p(x)
405404

Lib/test/test_math.py

+1
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ def testLog(self):
11461146
self.ftest('log(1/e)', math.log(1/math.e), -1)
11471147
self.ftest('log(1)', math.log(1), 0)
11481148
self.ftest('log(e)', math.log(math.e), 1)
1149+
self.ftest('log(e, None)', math.log(math.e, None), 1)
11491150
self.ftest('log(32,2)', math.log(32,2), 5)
11501151
self.ftest('log(10**40, 10)', math.log(10**40, 10), 40)
11511152
self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:func:`~math.log` and :func:`~cmath.log` support default base=None values.

Modules/clinic/cmathmodule.c.h

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/mathmodule.c.h

+19-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/cmathmodule.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -952,23 +952,24 @@ cmath_tanh_impl(PyObject *module, Py_complex z)
952952
cmath.log
953953
954954
z as x: Py_complex
955-
base as y_obj: object = NULL
955+
base as y_obj: object = None
956956
/
957957
958958
log(z[, base]) -> the logarithm of z to the given base.
959959
960-
If the base not specified, returns the natural logarithm (base e) of z.
960+
If the base is not specified or is None, returns the
961+
natural logarithm (base e) of z.
961962
[clinic start generated code]*/
962963

963964
static PyObject *
964965
cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj)
965-
/*[clinic end generated code: output=4effdb7d258e0d94 input=230ed3a71ecd000a]*/
966+
/*[clinic end generated code: output=4effdb7d258e0d94 input=e7db51859ebf70bf]*/
966967
{
967968
Py_complex y;
968969

969970
errno = 0;
970971
x = c_log(x);
971-
if (y_obj != NULL) {
972+
if (y_obj != Py_None) {
972973
y = PyComplex_AsCComplex(y_obj);
973974
if (PyErr_Occurred()) {
974975
return NULL;

Modules/mathmodule.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -2366,26 +2366,24 @@ loghelper(PyObject* arg, double (*func)(double))
23662366
math.log
23672367
23682368
x: object
2369-
[
2370-
base: object(c_default="NULL") = math.e
2371-
]
2369+
base: object = None
23722370
/
23732371
23742372
Return the logarithm of x to the given base.
23752373
2376-
If the base not specified, returns the natural logarithm (base e) of x.
2374+
If the base is not specified or is None, returns the natural
2375+
logarithm (base e) of x.
23772376
[clinic start generated code]*/
23782377

23792378
static PyObject *
2380-
math_log_impl(PyObject *module, PyObject *x, int group_right_1,
2381-
PyObject *base)
2382-
/*[clinic end generated code: output=7b5a39e526b73fc9 input=0f62d5726cbfebbd]*/
2379+
math_log_impl(PyObject *module, PyObject *x, PyObject *base)
2380+
/*[clinic end generated code: output=1dead263cbb1e854 input=ef032cc9837943e1]*/
23832381
{
23842382
PyObject *num, *den;
23852383
PyObject *ans;
23862384

23872385
num = loghelper(x, m_log);
2388-
if (num == NULL || base == NULL)
2386+
if (num == NULL || base == Py_None)
23892387
return num;
23902388

23912389
den = loghelper(base, m_log);

0 commit comments

Comments
 (0)