Skip to content

Commit

Permalink
fix JuliaLang#19182: convert([Un]Signed, x::BigInt) (JuliaLang#23474)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Sep 8, 2017
1 parent bc12af5 commit 22987e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ widen(::Type{BigInt}) = BigInt
signed(x::BigInt) = x

convert(::Type{BigInt}, x::BigInt) = x
convert(::Type{Signed}, x::BigInt) = x

hastypemax(::Type{BigInt}) = false

Expand Down Expand Up @@ -323,7 +324,7 @@ end

rem(x::Integer, ::Type{BigInt}) = convert(BigInt, x)

function convert(::Type{T}, x::BigInt) where T<:Unsigned
function convert(::Type{T}, x::BigInt) where T<:Base.BitUnsigned
if sizeof(T) < sizeof(Limb)
convert(T, convert(Limb,x))
else
Expand All @@ -332,7 +333,7 @@ function convert(::Type{T}, x::BigInt) where T<:Unsigned
end
end

function convert(::Type{T}, x::BigInt) where T<:Signed
function convert(::Type{T}, x::BigInt) where T<:Base.BitSigned
n = abs(x.size)
if sizeof(T) < sizeof(Limb)
SLimb = typeof(Signed(one(Limb)))
Expand Down
7 changes: 7 additions & 0 deletions test/bigint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,10 @@ end

@test BigInt <: Signed
@test big(1) isa Signed

let x = big(1)
@test signed(x) === x
@test convert(Signed, x) === x
@test Signed(x) === x
@test_throws MethodError convert(Unsigned, x) # could change in the future
end

0 comments on commit 22987e3

Please sign in to comment.