Skip to content

Commit

Permalink
widen Int8 and Int16 to Int instead of Int32 (#26859)
Browse files Browse the repository at this point in the history
This is consistent with `sum` and less arbitrary.
  • Loading branch information
JeffBezanson committed Apr 20, 2018
1 parent 2953183 commit 367bc96
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,10 @@ typemax(::Type{UInt64}) = 0xffffffffffffffff
@eval typemin(::Type{Int128} ) = $(convert(Int128, 1) << 127)
@eval typemax(::Type{Int128} ) = $(bitcast(Int128, typemax(UInt128) >> 1))

widen(::Type{<:Union{Int8, Int16}}) = Int32
widen(::Type{<:Union{Int8, Int16}}) = Int
widen(::Type{Int32}) = Int64
widen(::Type{Int64}) = Int128
widen(::Type{<:Union{UInt8, UInt16}}) = UInt32
widen(::Type{<:Union{UInt8, UInt16}}) = UInt
widen(::Type{UInt32}) = UInt64
widen(::Type{UInt64}) = UInt128

Expand Down
8 changes: 4 additions & 4 deletions test/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ end
end
end
@testset "widen/widemul" begin
@test widen(UInt8(3)) === UInt32(3)
@test widen(UInt16(3)) === UInt32(3)
@test widen(UInt8(3)) === UInt(3)
@test widen(UInt16(3)) === UInt(3)
@test widen(UInt32(3)) === UInt64(3)
@test widen(UInt64(3)) === UInt128(3)
@test widen(UInt128(3)) == 3
@test typeof(widen(UInt128(3))) == BigInt

@test widen(Int8(-3)) === Int32(-3)
@test widen(Int16(-3)) === Int32(-3)
@test widen(Int8(-3)) === Int(-3)
@test widen(Int16(-3)) === Int(-3)
@test widen(Int32(-3)) === Int64(-3)
@test widen(Int64(-3)) === Int128(-3)
@test widen(Int128(-3)) == -3
Expand Down
2 changes: 1 addition & 1 deletion test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ end
@testset "widen and widemul" begin
@test widen(1.5f0) === 1.5
@test widen(Int32(42)) === Int64(42)
@test widen(Int8) === Int32
@test widen(Int8) === Int
@test widen(Int64) === Int128
@test widen(Float32) === Float64
@test widen(Float16) === Float32
Expand Down

0 comments on commit 367bc96

Please sign in to comment.