Skip to content

Commit 4cecaba

Browse files
committed
Merge remote-tracking branch 'upstream/main' into fix-sizeof-for-int-subtypes
2 parents 9cd5d01 + c1b1f51 commit 4cecaba

27 files changed

+463
-385
lines changed

Doc/library/cmath.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ 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
9595
specified, returns the natural logarithm of *x*. There is one branch cut, from 0

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

Doc/using/windows.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ is printed. Now try changing the first line to be:
797797
Re-executing the command should now print the latest Python 3.x information.
798798
As with the above command-line examples, you can specify a more explicit
799799
version qualifier. Assuming you have Python 3.7 installed, try changing
800-
the first line to ``#! python3.7`` and you should find the |version|
800+
the first line to ``#! python3.7`` and you should find the 3.7
801801
version information printed.
802802

803803
Note that unlike interactive use, a bare "python" will use the latest

Include/cpython/longintrepr.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,14 @@ typedef long stwodigits; /* signed variant of twodigits */
7979
aware that ints abuse ob_size's sign bit.
8080
*/
8181

82-
struct _longobject {
83-
PyObject_VAR_HEAD
82+
typedef struct _PyLongValue {
83+
Py_ssize_t ob_size; /* Number of items in variable part */
8484
digit ob_digit[1];
85+
} _PyLongValue;
86+
87+
struct _longobject {
88+
PyObject_HEAD
89+
_PyLongValue long_value;
8590
};
8691

8792
PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);

Include/internal/pycore_runtime_init.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ extern "C" {
149149

150150
#define _PyLong_DIGIT_INIT(val) \
151151
{ \
152-
_PyVarObject_IMMORTAL_INIT(&PyLong_Type, \
153-
((val) == 0 ? 0 : ((val) > 0 ? 1 : -1))), \
154-
.ob_digit = { ((val) >= 0 ? (val) : -(val)) }, \
152+
.ob_base = _PyObject_IMMORTAL_INIT(&PyLong_Type), \
153+
.long_value = { \
154+
((val) == 0 ? 0 : ((val) > 0 ? 1 : -1)), \
155+
{ ((val) >= 0 ? (val) : -(val)) }, \
156+
} \
155157
}
156158

157159
#define _PyBytes_SIMPLE_INIT(CH, LEN) \

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Refactor the ``PyLongObject`` struct into a normal Python object header and
2+
a ``PyLongValue`` struct.
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/_decimal/_decimal.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,16 +2171,16 @@ dec_from_long(PyTypeObject *type, PyObject *v,
21712171
}
21722172

21732173
if (len == 1) {
2174-
_dec_settriple(dec, sign, *l->ob_digit, 0);
2174+
_dec_settriple(dec, sign, *l->long_value.ob_digit, 0);
21752175
mpd_qfinalize(MPD(dec), ctx, status);
21762176
return dec;
21772177
}
21782178

21792179
#if PYLONG_BITS_IN_DIGIT == 30
2180-
mpd_qimport_u32(MPD(dec), l->ob_digit, len, sign, PyLong_BASE,
2180+
mpd_qimport_u32(MPD(dec), l->long_value.ob_digit, len, sign, PyLong_BASE,
21812181
ctx, status);
21822182
#elif PYLONG_BITS_IN_DIGIT == 15
2183-
mpd_qimport_u16(MPD(dec), l->ob_digit, len, sign, PyLong_BASE,
2183+
mpd_qimport_u16(MPD(dec), l->long_value.ob_digit, len, sign, PyLong_BASE,
21842184
ctx, status);
21852185
#else
21862186
#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"
@@ -3543,11 +3543,11 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
35433543
return NULL;
35443544
}
35453545

3546-
memcpy(pylong->ob_digit, ob_digit, n * sizeof(digit));
3546+
memcpy(pylong->long_value.ob_digit, ob_digit, n * sizeof(digit));
35473547
mpd_free(ob_digit);
35483548

35493549
i = n;
3550-
while ((i > 0) && (pylong->ob_digit[i-1] == 0)) {
3550+
while ((i > 0) && (pylong->long_value.ob_digit[i-1] == 0)) {
35513551
i--;
35523552
}
35533553

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.

0 commit comments

Comments
 (0)