Skip to content
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

Silent overflow in converting BigInt to Int128 #6164

Closed
jiahao opened this issue Mar 14, 2014 · 3 comments
Closed

Silent overflow in converting BigInt to Int128 #6164

jiahao opened this issue Mar 14, 2014 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@jiahao
Copy link
Member

jiahao commented Mar 14, 2014

As uncovered in #6163:

julia> convert(Int64, BigInt("172293789645374271893931539237738556000"))
ERROR: InexactError()
 in convert at gmp.jl:108

julia> convert(Int128, BigInt("172293789645374271893931539237738556000"))
167988577275564191569443068194029655456
@jiahao jiahao added the bug label Mar 14, 2014
@jiahao
Copy link
Member Author

jiahao commented Mar 14, 2014

As it so happens, this number is Uint128-representable, thus causing the silent overflow in this method:

julia> typemax(Uint128) > BigInt("172293789645374271893931539237738556000") > typemax(Int128)
true

@jiahao
Copy link
Member Author

jiahao commented Mar 14, 2014

julia> convert(Uint128, BigInt("172293789645374271893931539237738556000"))
0x819e93add1572fe4413993ece0f2aa60

The copysign is interfering with the expected wraparound behavior:

julia> convert(Int16, 0xffff)
-1

@JeffBezanson
Copy link
Member

All of our integer conversions are unchecked (#5413). I'm not sure why that one conversion has an InexactError but it might have to do with the behavior of GMP's API here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants