-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix big(1)^big(-1) #50821
Fix big(1)^big(-1) #50821
Conversation
Co-authored-by: Sukera <11753998+Seelengrab@users.noreply.github.com>
@test (big(i)^big(j)) % Int8 === int8_res | ||
else | ||
# Test both have exception of the same type | ||
@test_throws typeof(int8_res) big(i)^big(j) |
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.
According to my local tests, it is actually possible to check for int8_res
directly, which would ensure the error message itself is also the same, helping ensure the error originated from the same location. Is there a reason you prefer only testing the type?
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 error messages for BigInt and Int8 are currently different. This is because Int8 uses throw_domerr_powbysq(x, p)
while BigInt has a custom message.
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.
Ah, good point.. Then this is good to go, I think.
This PR gives BigInt exponentiation the same edge-case behavior as other integer exponentiation.
The normal integer exponentiation checks if
x
is1
or-1
before erroring if the power is negative.julia/base/intfuncs.jl
Lines 283 to 287 in 9f9e989
With this PR
big(1)^big(-1) == 1
,big(-1)^big(-1) == -1
andbig(-1)^big(-2) == 1