-
-
Notifications
You must be signed in to change notification settings - Fork 15
Fix: Making pow compatible with cpython pow signature
#251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
juntyr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
| { | ||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 integersThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining.
closes #249