mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
This reverts commit 0ef92d9793
.
This commit is contained in:
parent
19ac43629e
commit
0672a6c23b
8 changed files with 47 additions and 42 deletions
|
@ -89,7 +89,7 @@ Power and logarithmic functions
|
||||||
logarithms.
|
logarithms.
|
||||||
|
|
||||||
|
|
||||||
.. function:: log(x, base=None)
|
.. function:: log(x[, base])
|
||||||
|
|
||||||
Returns the logarithm of *x* to the given *base*. If the *base* is not
|
Returns the logarithm of *x* to the given *base*. If the *base* is not
|
||||||
specified, returns the natural logarithm of *x*. There is one branch cut, from 0
|
specified, returns the natural logarithm of *x*. There is one branch cut, from 0
|
||||||
|
|
|
@ -393,12 +393,13 @@ Power and logarithmic functions
|
||||||
.. versionadded:: 3.2
|
.. versionadded:: 3.2
|
||||||
|
|
||||||
|
|
||||||
.. function:: log(x, base=None)
|
.. function:: log(x[, base])
|
||||||
|
|
||||||
Return the logarithm of *x* to the given *base*.
|
With one argument, return the natural logarithm of *x* (to base *e*).
|
||||||
|
|
||||||
|
With two arguments, return the logarithm of *x* to the given *base*,
|
||||||
|
calculated as ``log(x)/log(base)``.
|
||||||
|
|
||||||
If the *base* is not specified, returns the natural
|
|
||||||
logarithm (base *e*) of *x*.
|
|
||||||
|
|
||||||
.. function:: log1p(x)
|
.. function:: log1p(x)
|
||||||
|
|
||||||
|
|
|
@ -1146,7 +1146,6 @@ class MathTests(unittest.TestCase):
|
||||||
self.ftest('log(1/e)', math.log(1/math.e), -1)
|
self.ftest('log(1/e)', math.log(1/math.e), -1)
|
||||||
self.ftest('log(1)', math.log(1), 0)
|
self.ftest('log(1)', math.log(1), 0)
|
||||||
self.ftest('log(e)', math.log(math.e), 1)
|
self.ftest('log(e)', math.log(math.e), 1)
|
||||||
self.ftest('log(e, None)', math.log(math.e, None), 1)
|
|
||||||
self.ftest('log(32,2)', math.log(32,2), 5)
|
self.ftest('log(32,2)', math.log(32,2), 5)
|
||||||
self.ftest('log(10**40, 10)', math.log(10**40, 10), 40)
|
self.ftest('log(10**40, 10)', math.log(10**40, 10), 40)
|
||||||
self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2)
|
self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2)
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
:func:`~math.log` and :func:`~cmath.log` support default base=None values.
|
|
9
Modules/clinic/cmathmodule.c.h
generated
9
Modules/clinic/cmathmodule.c.h
generated
|
@ -639,13 +639,12 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(cmath_log__doc__,
|
PyDoc_STRVAR(cmath_log__doc__,
|
||||||
"log($module, z, base=None, /)\n"
|
"log($module, z, base=<unrepresentable>, /)\n"
|
||||||
"--\n"
|
"--\n"
|
||||||
"\n"
|
"\n"
|
||||||
"log(z[, base]) -> the logarithm of z to the given base.\n"
|
"log(z[, base]) -> the logarithm of z to the given base.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"If the base is not specified or is None, returns the\n"
|
"If the base not specified, returns the natural logarithm (base e) of z.");
|
||||||
"natural logarithm (base e) of z.");
|
|
||||||
|
|
||||||
#define CMATH_LOG_METHODDEF \
|
#define CMATH_LOG_METHODDEF \
|
||||||
{"log", _PyCFunction_CAST(cmath_log), METH_FASTCALL, cmath_log__doc__},
|
{"log", _PyCFunction_CAST(cmath_log), METH_FASTCALL, cmath_log__doc__},
|
||||||
|
@ -658,7 +657,7 @@ cmath_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
Py_complex x;
|
Py_complex x;
|
||||||
PyObject *y_obj = Py_None;
|
PyObject *y_obj = NULL;
|
||||||
|
|
||||||
if (!_PyArg_CheckPositional("log", nargs, 1, 2)) {
|
if (!_PyArg_CheckPositional("log", nargs, 1, 2)) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -983,4 +982,4 @@ skip_optional_kwonly:
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=2630f8740909a8f7 input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=0146c656e67f5d5f input=a9049054013a1b77]*/
|
||||||
|
|
44
Modules/clinic/mathmodule.c.h
generated
44
Modules/clinic/mathmodule.c.h
generated
|
@ -187,37 +187,43 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(math_log__doc__,
|
PyDoc_STRVAR(math_log__doc__,
|
||||||
"log($module, x, base=None, /)\n"
|
"log(x, [base=math.e])\n"
|
||||||
"--\n"
|
|
||||||
"\n"
|
|
||||||
"Return the logarithm of x to the given base.\n"
|
"Return the logarithm of x to the given base.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"If the base is not specified or is None, returns the natural\n"
|
"If the base not specified, returns the natural logarithm (base e) of x.");
|
||||||
"logarithm (base e) of x.");
|
|
||||||
|
|
||||||
#define MATH_LOG_METHODDEF \
|
#define MATH_LOG_METHODDEF \
|
||||||
{"log", _PyCFunction_CAST(math_log), METH_FASTCALL, math_log__doc__},
|
{"log", (PyCFunction)math_log, METH_VARARGS, math_log__doc__},
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
math_log_impl(PyObject *module, PyObject *x, PyObject *base);
|
math_log_impl(PyObject *module, PyObject *x, int group_right_1,
|
||||||
|
PyObject *base);
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
math_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
math_log(PyObject *module, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
PyObject *x;
|
PyObject *x;
|
||||||
PyObject *base = Py_None;
|
int group_right_1 = 0;
|
||||||
|
PyObject *base = NULL;
|
||||||
|
|
||||||
if (!_PyArg_CheckPositional("log", nargs, 1, 2)) {
|
switch (PyTuple_GET_SIZE(args)) {
|
||||||
goto exit;
|
case 1:
|
||||||
|
if (!PyArg_ParseTuple(args, "O:log", &x)) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (!PyArg_ParseTuple(args, "OO:log", &x, &base)) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
group_right_1 = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
PyErr_SetString(PyExc_TypeError, "math.log requires 1 to 2 arguments");
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
x = args[0];
|
return_value = math_log_impl(module, x, group_right_1, base);
|
||||||
if (nargs < 2) {
|
|
||||||
goto skip_optional;
|
|
||||||
}
|
|
||||||
base = args[1];
|
|
||||||
skip_optional:
|
|
||||||
return_value = math_log_impl(module, x, base);
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
|
@ -948,4 +954,4 @@ math_ulp(PyObject *module, PyObject *arg)
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=afec63ebb0da709a input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=899211ec70e4506c input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -952,24 +952,23 @@ cmath_tanh_impl(PyObject *module, Py_complex z)
|
||||||
cmath.log
|
cmath.log
|
||||||
|
|
||||||
z as x: Py_complex
|
z as x: Py_complex
|
||||||
base as y_obj: object = None
|
base as y_obj: object = NULL
|
||||||
/
|
/
|
||||||
|
|
||||||
log(z[, base]) -> the logarithm of z to the given base.
|
log(z[, base]) -> the logarithm of z to the given base.
|
||||||
|
|
||||||
If the base is not specified or is None, returns the
|
If the base not specified, returns the natural logarithm (base e) of z.
|
||||||
natural logarithm (base e) of z.
|
|
||||||
[clinic start generated code]*/
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj)
|
cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj)
|
||||||
/*[clinic end generated code: output=4effdb7d258e0d94 input=e7db51859ebf70bf]*/
|
/*[clinic end generated code: output=4effdb7d258e0d94 input=230ed3a71ecd000a]*/
|
||||||
{
|
{
|
||||||
Py_complex y;
|
Py_complex y;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
x = c_log(x);
|
x = c_log(x);
|
||||||
if (y_obj != Py_None) {
|
if (y_obj != NULL) {
|
||||||
y = PyComplex_AsCComplex(y_obj);
|
y = PyComplex_AsCComplex(y_obj);
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -2366,24 +2366,26 @@ loghelper(PyObject* arg, double (*func)(double))
|
||||||
math.log
|
math.log
|
||||||
|
|
||||||
x: object
|
x: object
|
||||||
base: object = None
|
[
|
||||||
|
base: object(c_default="NULL") = math.e
|
||||||
|
]
|
||||||
/
|
/
|
||||||
|
|
||||||
Return the logarithm of x to the given base.
|
Return the logarithm of x to the given base.
|
||||||
|
|
||||||
If the base is not specified or is None, returns the natural
|
If the base not specified, returns the natural logarithm (base e) of x.
|
||||||
logarithm (base e) of x.
|
|
||||||
[clinic start generated code]*/
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
math_log_impl(PyObject *module, PyObject *x, PyObject *base)
|
math_log_impl(PyObject *module, PyObject *x, int group_right_1,
|
||||||
/*[clinic end generated code: output=1dead263cbb1e854 input=ef032cc9837943e1]*/
|
PyObject *base)
|
||||||
|
/*[clinic end generated code: output=7b5a39e526b73fc9 input=0f62d5726cbfebbd]*/
|
||||||
{
|
{
|
||||||
PyObject *num, *den;
|
PyObject *num, *den;
|
||||||
PyObject *ans;
|
PyObject *ans;
|
||||||
|
|
||||||
num = loghelper(x, m_log);
|
num = loghelper(x, m_log);
|
||||||
if (num == NULL || base == Py_None)
|
if (num == NULL || base == NULL)
|
||||||
return num;
|
return num;
|
||||||
|
|
||||||
den = loghelper(base, m_log);
|
den = loghelper(base, m_log);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue