gh-89381: Fix invalid signatures of math/cmath.log (#101404) · python/cpython@0ef92d9 · GitHub
Skip to content

Commit 0ef92d9

Browse files
authored
gh-89381: Fix invalid signatures of math/cmath.log (#101404)
1 parent 666c084 commit 0ef92d9

8 files changed

Lines changed: 42 additions & 47 deletions

File tree

Doc/library/cmath.rst

Lines changed: 1 addition & 1 deletion

Doc/library/math.rst

Lines changed: 4 additions & 5 deletions
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, returns the natural
401+
logarithm (base *e*) of *x*.
403402

404403
.. function:: log1p(x)
405404

Lib/test/test_math.py

Lines changed: 1 addition & 0 deletions
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)
Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/mathmodule.c.h

Lines changed: 19 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/cmathmodule.c

Lines changed: 5 additions & 4 deletions
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

Lines changed: 6 additions & 8 deletions

0 commit comments

Comments
 (0)