I was surprised when I discovered the following when I was trying to do some fixed-point arithmetics
julia> UInt64(1) - 2
0xffffffffffffffff
julia> UInt32(1) - 2
-1
julia> UInt16(1) - 2
-1
This (inconsistent ?) behavior seems intentional. I found these promotion rules in base/int.jl
promote_rule(::Type{UInt32}, ::Type{Int64}) = Int64
#= ... =#
for T in BitSigned_types
@eval promote_rule{S<:Union{UInt8,UInt16}}(::Type{S}, ::Type{$T}) =
$(sizeof(T) < sizeof(Int) ? Int : T)
end
#= ... =#
promote_rule{T<:BitSigned64}(::Type{UInt64}, ::Type{T}) = UInt64
I’m sure there is some rationale behind this, as there usually is. But, I can’t see it.