Fix: Making pow compatible with cpython pow signature#251
Fix: Making pow compatible with cpython pow signature#251ngoldbaum merged 1 commit intonumpy:mainfrom
pow compatible with cpython pow signature#251Conversation
| { | ||
| if (mod != Py_None) { | ||
| PyErr_SetString(PyExc_TypeError, | ||
| "pow() 3rd argument not allowed unless all arguments are integers"); |
There was a problem hiding this comment.
The way the if statement above is written, the bit starting with "unless" is incorrect unless I'm missing something. Not sure if you meant to implement what's in the error or if the error is wrong.
There was a problem hiding this comment.
Cpython's pow function take 3 args but the last arg is only valid if the inputs are integers, for float values it passes the py_none there.
quaddtype is floating-point so we anyways don't need that argument and if in case somebody explicitly called pow with a 3rd argument (mod) then it'll be a mistake and error out
There was a problem hiding this comment.
This is the standard behaviour so we are in this PR implementing the same
In [5]: pow(2.0, 1,2)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 pow(2.0, 1,2)
TypeError: pow() 3rd argument not allowed unless all arguments are integersThere was a problem hiding this comment.
In quaddtype it should be as
In [2]: a = QuadPrecision("1")
In [3]: pow(a, 2)
Out[3]: QuadPrecision('1.0e+000', backend='sleef')
In [4]: pow(a, 2, 1)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[4], line 1
----> 1 pow(a, 2, 1)
TypeError: pow() 3rd argument not allowed unless all arguments are integers
closes numpy/numpy-quaddtype#3