-
-
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
DomainError in bigint_pow #9618
Comments
Not sure if this is a bug. From the source of
julia> Base.Meta.show_sexpr( :( big(3)^big(9)^big(9)^big(9)))
(:call, :^, (:call, :big, 3), (:call, :^, (:call, :big, 9), (:call, :^, (:call, :big, 9), (:call, :big, 9)))) If you really wanted right associative exponentiation, then I don't know if there is a way. GMP's exponentiation function is limited to an However, if you force the expression to be left associative, then you could do: julia> ((big(3)^9)^9)^9
662818605424187176105172864214479748588986673875686419462793267420461248113287928124072014075084032555900857691049061274135779819474602180821485109388447092848836753879024702508785576075431392037236950553064188689954912598712398079759040464474717726449363185622056684690721420542800623411346656785162817900551337542270334990205437212700131838846883 |
Thank you for the great reply. I'm not sure if this is a bug either. If this is not a bug, I think this issue should be considered a feature request for a slightly more informative error message. |
The answer to this computation has |
Yes, this is hitting a hard limit in GMP and, really, in the size of the universe. |
Technically speaking the current |
I'm uncertain if an OverflowError is any better than a DomainError without any more context. We cant catch exceptions by type, so this is really a message to the user. You are therefore assigning a lot of meaning to the words "DomainError" vs "OverflowError" . Which may be true in some domains (sic) but I'm not sure is universally understood. At least at first glance, I'll personally find these hard to disambiguate these from each other, or from "ArgumentError". In my mind, the goal is, when the user gets this error, does he understand what is wrong without reading library code? |
To me However, the See also #8286, where doing very large arithmetic in GMP leads to nasty |
If y in (x::BigInt)^y exceeds typemax of Uint and |x|>1, the result will overflow. In this case, return OverflowError. Otherwise retain the current behavior of returning a DomainError, unless if x==0, in which case just return 0.
If y in (x::BigInt)^y exceeds typemax of Uint and |x|>1, the result will overflow. In this case, return OverflowError. Otherwise retain the current behavior of returning a DomainError, unless if x==0, in which case just return 0.
If y in (x::BigInt)^y exceeds typemax of Uint and |x|>1, the result will overflow. In this case, return OverflowError. Otherwise retain the current behavior of returning a DomainError, unless if x==0, in which case just return 0.
big(3)^big(9)^big(9)^big(9)
gives
ERROR: DomainError in bigint_pow at gmp.jl:352 in ^ at gmp.jl:356
This is for Julia 0.3.4 on 64-bit Arch Linux.
The text was updated successfully, but these errors were encountered: