I am trying to find the actual implementation of math.pow in Python3 (3.7.3) on Ubuntu 18.04 LTS (Bionic Beaver).
The Python doc says the math module
provides access to the mathematical functions defined by the C standard.
This post says the math module
is usually included in OS distributions. ... many microprocessors have specialised instructions for some of these operations, and your compiler may well make use of those rather than jumping to the implementation in the C library.
So, there are 3 possible implementations Python, Ubuntu, microprocessors.
I searched python math module source code, and then google got me the mathmodule.c.
I didn't find the definition, declaration, wrapper, or implementation of math.pow in this mathmodule.c file.
I noticed that the mathmodule.c
includes some headers.
#include "Python.h"
#include "_math.h"
#include "clinic/mathmodule.c.h"
So, I searched them respectively, and got
"Python.h" is a "meta-include" file
Include nearly all Python header files
"_math.h" seems to be for Hyperbolic functions
the clue in "mathmodule.c.h" ends at math_pow_impl
static PyObject *
math_pow_impl(PyObject *module, double x, double y);
math_pow_impl is implemented at mathmodule.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);
seems to be the key, although mathmodule.c only uses the function rather than implementing this function, what is the next step I could try?
PS:
I also searched on my ubuntu (/usr/include/math.h
) and got no result contains "pow".