Skip to content

Commit

Permalink
Fix big(typemin(T)) (#29340)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Sep 26, 2018
1 parent 8d6c1ce commit 7698523
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ function BigInt(x::Integer)
z = MPZ.realloc2(nd)
s = sign(x)
s == -1 && (x = -x)
x = unsigned(x)
size = 0
limbnbits = sizeof(Limb) << 3
while nd > 0
Expand Down
8 changes: 8 additions & 0 deletions test/bigint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,11 @@ end
y = rand(UInt128)
@test BigInt(y) % UInt128 === y
end

@testset "conversion from typemin(T)" begin
@test big(Int8(-128)) == big"-128"
@test big(Int16(-32768)) == big"-32768"
@test big(Int32(-2147483648)) == big"-2147483648"
@test big(Int64(-9223372036854775808)) == big"-9223372036854775808"
@test big(Int128(-170141183460469231731687303715884105728)) == big"-170141183460469231731687303715884105728"
end

0 comments on commit 7698523

Please sign in to comment.