为什么我不能在 pypy 中使用 pow() 函数

why i can't use pow() function in pypy

a = pow(4,-1,3)
print(a)

该代码在 Python3.7 中有效。 但它在 pypy3 中不起作用。 这是错误信息:

TypeError: pow() 2nd argument cannot be negative when 3rd argument specified

我想 pow() 函数在第二个参数中使用 -1,在第三个参数中使用整数 帮帮我!

当它是 3.8 功能时,它如何与 Python 3.7 一起使用?

引自https://docs.python.org/3/whatsnew/3.8.html :

For integers, the three-argument form of the pow() function now permits the exponent to be negative in the case where the base is relatively prime to the modulus. It then computes a modular inverse to the base when the exponent is -1, and a suitable power of that inverse for other negative exponents.

每晚构建 PyPy 3.8:

Python 3.8.10 (cfd47581da0a, Jul 29 2021, 10:16:09)
[PyPy 7.3.6-alpha0 with GCC 7.3.1 20180303 (Red Hat 7.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``running pypy-c translate.py is a
bit like watching a thriller movie, it could die at any time because of the
32-bit 4GB limit of RAM''
>>>> a = pow(4,-1,3)
>>>> print(a)
1

使用 CPython 3.7 你会得到预期的 ValueError:

Python 3.7.11 (default, Jun 29 2021, 16:09:17) 
[GCC 10.3.1 20210422 (Red Hat 10.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = pow(4,-1,3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: pow() 2nd argument cannot be negative when 3rd argument specified