如何在Ubuntu 18.04 LTS(Bionic Beaver)上的Python3(3.7.3)中找到math.pow的实际实现?

时间:2019-09-09 07:19:02

标签: python c python-3.x ubuntu

我正在尝试在Ubuntu 18.04 LTS(Bionic Beaver)的Python3(3.7.3)中找到math.pow的实际实现。

Python文档说数学模块

  

提供对C标准定义的数学函数的访问。

post说的是数学模块

  

通常包含在OS发行版中。 ...许多微处理器针对其中的某些操作提供了专门的指令,您的编译器可能会充分利用这些指令,而不是跳转到C库中的实现。

因此,有3种可能的实现方式,Python,Ubuntu,微处理器。

我搜索了python math module source code,然后谷歌给了我mathmodule.c

在此mathmodule.c文件中找不到math.pow的定义,声明,包装或实现。

我注意到mathmodule.c包含一些标题。

#include "Python.h"
#include "_math.h"

#include "clinic/mathmodule.c.h"

所以,我分别搜索了它们,并得到了

"Python.h"是“包含元数据”文件

  

包括几乎所有的Python头文件

"_math.h"似乎适用于双曲线functions

"mathmodule.c.h"中的线索以math_pow_impl结尾

static PyObject *
math_pow_impl(PyObject *module, double x, double y);

math_pow_implmathmodule.c上实现

static PyObject *
math_pow_impl(PyObject *module, double x, double y)
/*[clinic end generated code: output=fff93e65abccd6b0 input=c26f1f6075088bfd]*/
{
    double r;
    int odd_y;

...

errno = 0;
PyFPE_START_PROTECT("in math_pow", return 0);
r = pow(x, y);
PyFPE_END_PROTECT(r);

r = pow(x, y);似乎是关键,尽管mathmodule.c仅使用该功能而不是实现此功能,但下一步我可以尝试什么?

PS:

我还搜索了我的ubuntu(/usr/include/math.h),但没有结果包含“ pow”。

0 个答案:

没有答案