我很好奇,Python里面的pow函数是用啥算法写的,快速幂吗?你从哪知道的,在哪里能看到源码?
python的math函数应该是调用的C函数库。
如果你使用ide的话,点击函数跳转到math中,会发现在 math.pyi 文件中,pow函数只定义了函数头,没有具体实现。
而结合 math.doc 的提示,我们可以猜测math中的函数调用自C库。https://github.com/python/cpython/blob/3.10/Doc/library/math.rst
另外,python本就支持 **
运算,在 https://docs.python.org/zh-cn/3/library/math.html 中,说到 math.pow 与内置的 ** 运算符不同。
给三个可能有用的连接(毕竟我也不了解
https://www.zhihu.com/question/31259978/answer/51278279
https://stackoverflow.com/questions/8608587/finding-the-source-code-for-built-in-python-functions
https://github.com/python/cpython/blob/9ba33eec31596514a060964a9ff593e732807c13/Python/bltinmodule.c