diff --git a/base/abstractarray.jl b/base/abstractarray.jl index cdfa0abe14e6c..1163e0c3994b9 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -320,8 +320,8 @@ end float{T<:FloatingPoint}(x::AbstractArray{T}) = x complex{T<:Complex}(x::AbstractArray{T}) = x -float{T<:Integer64}(x::AbstractArray{T}) = convert(AbstractArray{typeof(float(zero(T)))}, x) -complex{T<:Union(Integer64,Float64,Float32,Float16)}(x::AbstractArray{T}) = +float{T<:IntegerUpto64}(x::AbstractArray{T}) = convert(AbstractArray{typeof(float(zero(T)))}, x) +complex{T<:Union(IntegerUpto64,Float64,Float32,Float16)}(x::AbstractArray{T}) = convert(AbstractArray{typeof(complex(zero(T)))}, x) function float(A::AbstractArray) diff --git a/base/hashing2.jl b/base/hashing2.jl index 342e2dc6c8a93..7d640a885307b 100644 --- a/base/hashing2.jl +++ b/base/hashing2.jl @@ -129,7 +129,7 @@ end ## streamlined hashing for smallish rational types ## -function hash{T<:Integer64}(x::Rational{T}, h::Uint) +function hash{T<:IntegerUpto64}(x::Rational{T}, h::Uint) num, den = Base.num(x), Base.den(x) den == 1 && return hash(num, h) den == 0 && return hash(ifelse(num > 0, Inf, -Inf), h) diff --git a/base/int.jl b/base/int.jl index 3a761b3072b18..2cd3e809eddbd 100644 --- a/base/int.jl +++ b/base/int.jl @@ -1,51 +1,19 @@ ## type aliases ## -if Int === Int32 -typealias SmallSigned Union(Int8,Int16) -typealias SmallUnsigned Union(Uint8,Uint16) -else -typealias SmallSigned Union(Int8,Int16,Int32) -typealias SmallUnsigned Union(Uint8,Uint16,Uint32) -end +typealias SignedUpto64 Union(Int8,Int16,Int32,Int64) +typealias UnsignedUpto64 Union(Uint8,Uint16,Uint32,Uint64) +typealias IntegerUpto64 Union(SignedUpto64,UnsignedUpto64) + +typealias SignedUpto128 Union(SignedUpto64,Int128) +typealias UnsignedUpto128 Union(UnsignedUpto64,Uint128) +typealias IntegerUpto128 Union(SignedUpto128,UnsignedUpto128) ## integer arithmetic ## --(x::SmallSigned) = -int(x) --(x::SmallUnsigned) = -uint(x) - -+{T<:SmallSigned}(x::T, y::T) = int(x) + int(y) --{T<:SmallSigned}(x::T, y::T) = int(x) - int(y) -*{T<:SmallSigned}(x::T, y::T) = int(x) * int(y) - -+{T<:SmallUnsigned}(x::T, y::T) = uint(x) + uint(y) --{T<:SmallUnsigned}(x::T, y::T) = uint(x) - uint(y) -*{T<:SmallUnsigned}(x::T, y::T) = uint(x) * uint(y) - --(x::Int) = box(Int,neg_int(unbox(Int,x))) --(x::Uint) = box(Uint,neg_int(unbox(Uint,x))) --(x::Int64) = box(Int64,neg_int(unbox(Int64,x))) --(x::Uint64) = box(Uint64,neg_int(unbox(Uint64,x))) --(x::Int128) = box(Int128,neg_int(unbox(Int128,x))) --(x::Uint128) = box(Uint128,neg_int(unbox(Uint128,x))) - -+(x::Int, y::Int) = box(Int,add_int(unbox(Int,x),unbox(Int,y))) -+(x::Uint, y::Uint) = box(Uint,add_int(unbox(Uint,x),unbox(Uint,y))) -+(x::Int64, y::Int64) = box(Int64,add_int(unbox(Int64,x),unbox(Int64,y))) -+(x::Uint64, y::Uint64) = box(Uint64,add_int(unbox(Uint64,x),unbox(Uint64,y))) -+(x::Int128, y::Int128) = box(Int128,add_int(unbox(Int128,x),unbox(Int128,y))) -+(x::Uint128, y::Uint128) = box(Uint128,add_int(unbox(Uint128,x),unbox(Uint128,y))) - --(x::Int, y::Int) = box(Int,sub_int(unbox(Int,x),unbox(Int,y))) --(x::Uint, y::Uint) = box(Uint,sub_int(unbox(Uint,x),unbox(Uint,y))) --(x::Int64, y::Int64) = box(Int64,sub_int(unbox(Int64,x),unbox(Int64,y))) --(x::Uint64, y::Uint64) = box(Uint64,sub_int(unbox(Uint64,x),unbox(Uint64,y))) --(x::Int128, y::Int128) = box(Int128,sub_int(unbox(Int128,x),unbox(Int128,y))) --(x::Uint128, y::Uint128) = box(Uint128,sub_int(unbox(Uint128,x),unbox(Uint128,y))) - -*(x::Int, y::Int) = box(Int,mul_int(unbox(Int,x),unbox(Int,y))) -*(x::Uint, y::Uint) = box(Uint,mul_int(unbox(Uint,x),unbox(Uint,y))) -*(x::Int64, y::Int64) = box(Int64,mul_int(unbox(Int64,x),unbox(Int64,y))) -*(x::Uint64, y::Uint64) = box(Uint64,mul_int(unbox(Uint64,x),unbox(Uint64,y))) +-{T<:IntegerUpto128}(x::T) = box(T,neg_int(unbox(T,x))) ++{T<:IntegerUpto128}(x::T, y::T) = box(T,add_int(unbox(T,x),unbox(T,y))) +-{T<:IntegerUpto128}(x::T, y::T) = box(T,sub_int(unbox(T,x),unbox(T,y))) +*{T<:IntegerUpto64}(x::T, y::T) = box(T,mul_int(unbox(T,x),unbox(T,y))) /(x::Integer, y::Integer) = float(x)/float(y) inv(x::Integer) = float(one(x))/float(x) @@ -56,11 +24,8 @@ iseven(n::Integer) = !isodd(n) signbit(x::Integer) = x < 0 signbit(x::Unsigned) = false -flipsign(x::Int, y::Int) = box(Int,flipsign_int(unbox(Int,x),unbox(Int,y))) -flipsign(x::Int64, y::Int64) = box(Int64,flipsign_int(unbox(Int64,x),unbox(Int64,y))) -flipsign(x::Int128, y::Int128) = box(Int128,flipsign_int(unbox(Int128,x),unbox(Int128,y))) +flipsign{T<:SignedUpto128}(x::T, y::T) = box(T,flipsign_int(unbox(T,x),unbox(T,y))) -flipsign{T<:Signed}(x::T,y::T) = flipsign(int(x),int(y)) flipsign(x::Signed, y::Signed) = flipsign(promote(x,y)...) flipsign(x::Signed, y::Float32) = flipsign(x, reinterpret(Int32,y)) flipsign(x::Signed, y::Float64) = flipsign(x, reinterpret(Int64,y)) @@ -90,15 +55,12 @@ mod(x::Unsigned, y::Signed) = rem(y+signed(rem(x,y)),y) # Don't promote integers for div/rem/mod since there no danger of overflow, # while there is a substantial performance penalty to 64-bit promotion. -typealias Signed64 Union(Int8,Int16,Int32,Int64) -typealias Unsigned64 Union(Uint8,Uint16,Uint32,Uint64) -typealias Integer64 Union(Signed64,Unsigned64) -div{T<:Signed64} (x::T, y::T) = box(T,sdiv_int(unbox(T,x),unbox(T,y))) -div{T<:Unsigned64}(x::T, y::T) = box(T,udiv_int(unbox(T,x),unbox(T,y))) -rem{T<:Signed64} (x::T, y::T) = box(T,srem_int(unbox(T,x),unbox(T,y))) -rem{T<:Unsigned64}(x::T, y::T) = box(T,urem_int(unbox(T,x),unbox(T,y))) -mod{T<:Signed64} (x::T, y::T) = box(T,smod_int(unbox(T,x),unbox(T,y))) +div{T<:SignedUpto64} (x::T, y::T) = box(T,sdiv_int(unbox(T,x),unbox(T,y))) +div{T<:UnsignedUpto64}(x::T, y::T) = box(T,udiv_int(unbox(T,x),unbox(T,y))) +rem{T<:SignedUpto64} (x::T, y::T) = box(T,srem_int(unbox(T,x),unbox(T,y))) +rem{T<:UnsignedUpto64}(x::T, y::T) = box(T,urem_int(unbox(T,x),unbox(T,y))) +mod{T<:SignedUpto64} (x::T, y::T) = box(T,smod_int(unbox(T,x),unbox(T,y))) mod{T<:Unsigned}(x::T, y::T) = rem(x,y) @@ -107,133 +69,24 @@ fld{T<:Integer }(x::T, y::T) = div(x,y)-(signbit(x$y)&(rem(x,y)!=0)) ## integer bitwise operations ## -~(x::Int8 ) = box(Int8,not_int(unbox(Int8,x))) -~(x::Int16) = box(Int16,not_int(unbox(Int16,x))) -~(x::Int32) = box(Int32,not_int(unbox(Int32,x))) -~(x::Int64) = box(Int64,not_int(unbox(Int64,x))) -~(x::Int128) = box(Int128,not_int(unbox(Int128,x))) - -~(x::Uint8 ) = box(Uint8,not_int(unbox(Uint8,x))) -~(x::Uint16) = box(Uint16,not_int(unbox(Uint16,x))) -~(x::Uint32) = box(Uint32,not_int(unbox(Uint32,x))) -~(x::Uint64) = box(Uint64,not_int(unbox(Uint64,x))) -~(x::Uint128) = box(Uint128,not_int(unbox(Uint128,x))) - -(&)(x::Int8, y::Int8 ) = box(Int8,and_int(unbox(Int8,x),unbox(Int8,y))) -(&)(x::Int16, y::Int16) = box(Int16,and_int(unbox(Int16,x),unbox(Int16,y))) -(&)(x::Int32, y::Int32) = box(Int32,and_int(unbox(Int32,x),unbox(Int32,y))) -(&)(x::Int64, y::Int64) = box(Int64,and_int(unbox(Int64,x),unbox(Int64,y))) -(&)(x::Int128, y::Int128) = box(Int128,and_int(unbox(Int128,x),unbox(Int128,y))) - -(&)(x::Uint8, y::Uint8 ) = box(Uint8,and_int(unbox(Uint8,x),unbox(Uint8,y))) -(&)(x::Uint16, y::Uint16) = box(Uint16,and_int(unbox(Uint16,x),unbox(Uint16,y))) -(&)(x::Uint32, y::Uint32) = box(Uint32,and_int(unbox(Uint32,x),unbox(Uint32,y))) -(&)(x::Uint64, y::Uint64) = box(Uint64,and_int(unbox(Uint64,x),unbox(Uint64,y))) -(&)(x::Uint128, y::Uint128) = box(Uint128,and_int(unbox(Uint128,x),unbox(Uint128,y))) - -|(x::Int8, y::Int8) = box(Int8,or_int(unbox(Int8,x),unbox(Int8,y))) -|(x::Int16, y::Int16) = box(Int16,or_int(unbox(Int16,x),unbox(Int16,y))) -|(x::Int32, y::Int32) = box(Int32,or_int(unbox(Int32,x),unbox(Int32,y))) -|(x::Int64, y::Int64) = box(Int64,or_int(unbox(Int64,x),unbox(Int64,y))) -|(x::Int128, y::Int128) = box(Int128,or_int(unbox(Int128,x),unbox(Int128,y))) - -|(x::Uint8, y::Uint8) = box(Uint8,or_int(unbox(Uint8,x),unbox(Uint8,y))) -|(x::Uint16, y::Uint16) = box(Uint16,or_int(unbox(Uint16,x),unbox(Uint16,y))) -|(x::Uint32, y::Uint32) = box(Uint32,or_int(unbox(Uint32,x),unbox(Uint32,y))) -|(x::Uint64, y::Uint64) = box(Uint64,or_int(unbox(Uint64,x),unbox(Uint64,y))) -|(x::Uint128, y::Uint128) = box(Uint128,or_int(unbox(Uint128,x),unbox(Uint128,y))) - -($)(x::Int8, y::Int8) = box(Int8,xor_int(unbox(Int8,x),unbox(Int8,y))) -($)(x::Int16, y::Int16) = box(Int16,xor_int(unbox(Int16,x),unbox(Int16,y))) -($)(x::Int32, y::Int32) = box(Int32,xor_int(unbox(Int32,x),unbox(Int32,y))) -($)(x::Int64, y::Int64) = box(Int64,xor_int(unbox(Int64,x),unbox(Int64,y))) -($)(x::Int128, y::Int128) = box(Int128,xor_int(unbox(Int128,x),unbox(Int128,y))) - -($)(x::Uint8, y::Uint8) = box(Uint8,xor_int(unbox(Uint8,x),unbox(Uint8,y))) -($)(x::Uint16, y::Uint16) = box(Uint16,xor_int(unbox(Uint16,x),unbox(Uint16,y))) -($)(x::Uint32, y::Uint32) = box(Uint32,xor_int(unbox(Uint32,x),unbox(Uint32,y))) -($)(x::Uint64, y::Uint64) = box(Uint64,xor_int(unbox(Uint64,x),unbox(Uint64,y))) -($)(x::Uint128, y::Uint128) = box(Uint128,xor_int(unbox(Uint128,x),unbox(Uint128,y))) - -<<(x::Int8, y::Int32) = box(Int8,shl_int(unbox(Int8,x),unbox(Int32,y))) -<<(x::Int16, y::Int32) = box(Int16,shl_int(unbox(Int16,x),unbox(Int32,y))) -<<(x::Int32, y::Int32) = box(Int32,shl_int(unbox(Int32,x),unbox(Int32,y))) -<<(x::Int64, y::Int32) = box(Int64,shl_int(unbox(Int64,x),unbox(Int32,y))) -<<(x::Int128, y::Int32) = box(Int128,shl_int(unbox(Int128,x),unbox(Int32,y))) - -<<(x::Uint8, y::Int32) = box(Uint8,shl_int(unbox(Uint8,x),unbox(Int32,y))) -<<(x::Uint16, y::Int32) = box(Uint16,shl_int(unbox(Uint16,x),unbox(Int32,y))) -<<(x::Uint32, y::Int32) = box(Uint32,shl_int(unbox(Int32,x),unbox(Uint32,y))) -<<(x::Uint64, y::Int32) = box(Uint64,shl_int(unbox(Uint64,x),unbox(Int32,y))) -<<(x::Uint128, y::Int32) = box(Uint128,shl_int(unbox(Uint128,x),unbox(Int32,y))) - ->>(x::Int8, y::Int32) = box(Int8,ashr_int(unbox(Int8,x),unbox(Int32,y))) ->>(x::Int16, y::Int32) = box(Int16,ashr_int(unbox(Int16,x),unbox(Int32,y))) ->>(x::Int32, y::Int32) = box(Int32,ashr_int(unbox(Int32,x),unbox(Int32,y))) ->>(x::Int64, y::Int32) = box(Int64,ashr_int(unbox(Int64,x),unbox(Int32,y))) ->>(x::Int128, y::Int32) = box(Int128,ashr_int(unbox(Int128,x),unbox(Int32,y))) - ->>(x::Uint8, y::Int32) = box(Uint8,lshr_int(unbox(Uint8,x),unbox(Int32,y))) ->>(x::Uint16, y::Int32) = box(Uint16,lshr_int(unbox(Uint16,x),unbox(Int32,y))) ->>(x::Uint32, y::Int32) = box(Uint32,lshr_int(unbox(Int32,x),unbox(Uint32,y))) ->>(x::Uint64, y::Int32) = box(Uint64,lshr_int(unbox(Uint64,x),unbox(Int32,y))) ->>(x::Uint128, y::Int32) = box(Uint128,lshr_int(unbox(Uint128,x),unbox(Int32,y))) - ->>>(x::Int8, y::Int32) = box(Int8,lshr_int(unbox(Int8,x),unbox(Int32,y))) ->>>(x::Int16, y::Int32) = box(Int16,lshr_int(unbox(Int16,x),unbox(Int32,y))) ->>>(x::Int32, y::Int32) = box(Int32,lshr_int(unbox(Int32,x),unbox(Int32,y))) ->>>(x::Int64, y::Int32) = box(Int64,lshr_int(unbox(Int64,x),unbox(Int32,y))) ->>>(x::Int128, y::Int32) = box(Int128,lshr_int(unbox(Int128,x),unbox(Int32,y))) - ->>>(x::Uint8, y::Int32) = box(Uint8,lshr_int(unbox(Uint8,x),unbox(Int32,y))) ->>>(x::Uint16, y::Int32) = box(Uint16,lshr_int(unbox(Uint16,x),unbox(Int32,y))) ->>>(x::Uint32, y::Int32) = box(Uint32,lshr_int(unbox(Int32,x),unbox(Uint32,y))) ->>>(x::Uint64, y::Int32) = box(Uint64,lshr_int(unbox(Uint64,x),unbox(Int32,y))) ->>>(x::Uint128, y::Int32) = box(Uint128,lshr_int(unbox(Uint128,x),unbox(Int32,y))) +~{T<:IntegerUpto128}(x::T) = box(T,not_int(unbox(T,x))) +(&){T<:IntegerUpto128}(x::T, y::T) = box(T,and_int(unbox(T,x),unbox(T,y))) +(|){T<:IntegerUpto128}(x::T, y::T) = box(T,or_int(unbox(T,x),unbox(T,y))) +($){T<:IntegerUpto128}(x::T, y::T) = box(T,xor_int(unbox(T,x),unbox(T,y))) + +<<{T<:IntegerUpto128}(x::T, y::Int32) = box(T,shl_int(unbox(T,x),unbox(Int32,y))) +>>{T<:SignedUpto128}(x::T, y::Int32) = box(T,ashr_int(unbox(T,x),unbox(Int32,y))) +>>{T<:UnsignedUpto128}(x::T, y::Int32) = box(T,lshr_int(unbox(T,x),unbox(Int32,y))) +>>>{T<:IntegerUpto128} (x::T, y::Int32) = box(T,lshr_int(unbox(T,x),unbox(Int32,y))) bswap(x::Int8) = x bswap(x::Uint8) = x -bswap(x::Int16) = box(Int16,bswap_int(unbox(Int16,x))) -bswap(x::Uint16) = box(Uint16,bswap_int(unbox(Uint16,x))) -bswap(x::Int32) = box(Int32,bswap_int(unbox(Int32,x))) -bswap(x::Uint32) = box(Uint32,bswap_int(unbox(Uint32,x))) -bswap(x::Int64) = box(Int64,bswap_int(unbox(Int64,x))) -bswap(x::Uint64) = box(Uint64,bswap_int(unbox(Uint64,x))) -bswap(x::Int128) = box(Int128,bswap_int(unbox(Int128,x))) -bswap(x::Uint128) = box(Uint128,bswap_int(unbox(Uint128,x))) - -count_ones(x::Int8) = int(box(Int8,ctpop_int(unbox(Int8,x)))) -count_ones(x::Uint8) = int(box(Uint8,ctpop_int(unbox(Uint8,x)))) -count_ones(x::Int16) = int(box(Int16,ctpop_int(unbox(Int16,x)))) -count_ones(x::Uint16) = int(box(Uint16,ctpop_int(unbox(Uint16,x)))) -count_ones(x::Int32) = int(box(Int32,ctpop_int(unbox(Int32,x)))) -count_ones(x::Uint32) = int(box(Uint32,ctpop_int(unbox(Uint32,x)))) -count_ones(x::Int64) = int(box(Int64,ctpop_int(unbox(Int64,x)))) -count_ones(x::Uint64) = int(box(Uint64,ctpop_int(unbox(Uint64,x)))) -count_ones(x::Int128) = int(box(Int128,ctpop_int(unbox(Int128,x)))) -count_ones(x::Uint128) = int(box(Uint128,ctpop_int(unbox(Uint128,x)))) - -leading_zeros(x::Int8) = int(box(Int8,ctlz_int(unbox(Int8,x)))) -leading_zeros(x::Uint8) = int(box(Uint8,ctlz_int(unbox(Uint8,x)))) -leading_zeros(x::Int16) = int(box(Int16,ctlz_int(unbox(Int16,x)))) -leading_zeros(x::Uint16) = int(box(Uint16,ctlz_int(unbox(Uint16,x)))) -leading_zeros(x::Int32) = int(box(Int32,ctlz_int(unbox(Int32,x)))) -leading_zeros(x::Uint32) = int(box(Uint32,ctlz_int(unbox(Uint32,x)))) -leading_zeros(x::Int64) = int(box(Int64,ctlz_int(unbox(Int64,x)))) -leading_zeros(x::Uint64) = int(box(Uint64,ctlz_int(unbox(Uint64,x)))) -leading_zeros(x::Int128) = int(box(Int128,ctlz_int(unbox(Int128,x)))) -leading_zeros(x::Uint128) = int(box(Uint128,ctlz_int(unbox(Uint128,x)))) - -trailing_zeros(x::Int8) = int(box(Int8,cttz_int(unbox(Int8,x)))) -trailing_zeros(x::Uint8) = int(box(Uint8,cttz_int(unbox(Uint8,x)))) -trailing_zeros(x::Int16) = int(box(Int16,cttz_int(unbox(Int16,x)))) -trailing_zeros(x::Uint16) = int(box(Uint16,cttz_int(unbox(Uint16,x)))) -trailing_zeros(x::Int32) = int(box(Int32,cttz_int(unbox(Int32,x)))) -trailing_zeros(x::Uint32) = int(box(Uint32,cttz_int(unbox(Uint32,x)))) -trailing_zeros(x::Int64) = int(box(Int64,cttz_int(unbox(Int64,x)))) -trailing_zeros(x::Uint64) = int(box(Uint64,cttz_int(unbox(Uint64,x)))) -trailing_zeros(x::Int128) = int(box(Int128,cttz_int(unbox(Int128,x)))) -trailing_zeros(x::Uint128) = int(box(Uint128,cttz_int(unbox(Uint128,x)))) +typealias ByteSwapIntegers Union(Int16, Uint16, Int32, Uint32, Int64, Uint64, Int128, Uint128) +bswap{T<:ByteSwapIntegers}(x::T) = box(T,bswap_int(unbox(T,x))) + +count_ones{T<:IntegerUpto128}(x::T) = int(box(T,ctpop_int(unbox(T,x)))) +leading_zeros{T<:IntegerUpto128}(x::T) = int(box(T,ctlz_int(unbox(T,x)))) +trailing_zeros{T<:IntegerUpto128}(x::T) = int(box(T,cttz_int(unbox(T,x)))) count_zeros (x::Integer) = count_ones(~x) leading_ones (x::Integer) = leading_zeros(~x) @@ -241,29 +94,10 @@ trailing_ones(x::Integer) = trailing_zeros(~x) ## integer comparisons ## -<(x::Int8, y::Int8) = slt_int(unbox(Int8,x),unbox(Int8,y)) -<(x::Int16, y::Int16) = slt_int(unbox(Int16,x),unbox(Int16,y)) -<(x::Int32, y::Int32) = slt_int(unbox(Int32,x),unbox(Int32,y)) -<(x::Int64, y::Int64) = slt_int(unbox(Int64,x),unbox(Int64,y)) -<(x::Int128, y::Int128) = slt_int(unbox(Int128,x),unbox(Int128,y)) - -<(x::Uint8, y::Uint8) = ult_int(unbox(Uint8,x),unbox(Uint8,y)) -<(x::Uint16, y::Uint16) = ult_int(unbox(Uint16,x),unbox(Uint16,y)) -<(x::Uint32, y::Uint32) = ult_int(unbox(Uint32,x),unbox(Uint32,y)) -<(x::Uint64, y::Uint64) = ult_int(unbox(Uint64,x),unbox(Uint64,y)) -<(x::Uint128, y::Uint128) = ult_int(unbox(Uint128,x),unbox(Uint128,y)) - -<=(x::Int8, y::Int8) = sle_int(unbox(Int8,x),unbox(Int8,y)) -<=(x::Int16, y::Int16) = sle_int(unbox(Int16,x),unbox(Int16,y)) -<=(x::Int32, y::Int32) = sle_int(unbox(Int32,x),unbox(Int32,y)) -<=(x::Int64, y::Int64) = sle_int(unbox(Int64,x),unbox(Int64,y)) -<=(x::Int128, y::Int128) = sle_int(unbox(Int128,x),unbox(Int128,y)) - -<=(x::Uint8, y::Uint8) = ule_int(unbox(Uint8,x),unbox(Uint8,y)) -<=(x::Uint16, y::Uint16) = ule_int(unbox(Uint16,x),unbox(Uint16,y)) -<=(x::Uint32, y::Uint32) = ule_int(unbox(Uint32,x),unbox(Uint32,y)) -<=(x::Uint64, y::Uint64) = ule_int(unbox(Uint64,x),unbox(Uint64,y)) -<=(x::Uint128, y::Uint128) = ule_int(unbox(Uint128,x),unbox(Uint128,y)) +<{T<:SignedUpto128}(x::T, y::T) = slt_int(unbox(T,x),unbox(T,y)) +<{T<:UnsignedUpto128}(x::T, y::T) = ult_int(unbox(T,x),unbox(T,y)) +<={T<:SignedUpto128}(x::T, y::T) = sle_int(unbox(T,x),unbox(T,y)) +<={T<:UnsignedUpto128}(x::T, y::T) = ule_int(unbox(T,x),unbox(T,y)) ==(x::Signed, y::Unsigned) = (x >= 0) & (unsigned(x) == y) ==(x::Unsigned, y::Signed ) = (y >= 0) & (x == unsigned(y)) @@ -293,19 +127,10 @@ for to in _inttypes, from in _inttypes end end -for to in (Int8, Int16, Int32, Int64) - @eval begin - convert(::Type{$to}, x::Float32) = box($to,checked_fptosi($to,unbox(Float32,x))) - convert(::Type{$to}, x::Float64) = box($to,checked_fptosi($to,unbox(Float64,x))) - end -end - -for to in (Uint8, Uint16, Uint32, Uint64) - @eval begin - convert(::Type{$to}, x::Float32) = box($to,checked_fptoui($to,unbox(Float32,x))) - convert(::Type{$to}, x::Float64) = box($to,checked_fptoui($to,unbox(Float64,x))) - end -end +convert{T<:SignedUpto64}(::Type{T}, x::Float32) = box(T,checked_fptosi(T,unbox(Float32,x))) +convert{T<:SignedUpto64}(::Type{T}, x::Float64) = box(T,checked_fptosi(T,unbox(Float64,x))) +convert{T<:UnsignedUpto64}(::Type{T}, x::Float32) = box(T,checked_fptoui(T,unbox(Float32,x))) +convert{T<:UnsignedUpto64}(::Type{T}, x::Float64) = box(T,checked_fptoui(T,unbox(Float64,x))) function convert(::Type{Int128}, x::FloatingPoint) ax = abs(x) @@ -328,18 +153,18 @@ convert(::Type{Uint128}, x::Float32) = convert(Uint128, float64(x)) convert(::Type{Char}, x::Float32) = char(convert(Int, x)) convert(::Type{Char}, x::Float64) = char(convert(Int, x)) -convert(::Type{Signed}, x::Uint8 ) = convert(Int,x) -convert(::Type{Signed}, x::Uint16 ) = convert(Int,x) -convert(::Type{Signed}, x::Uint32 ) = convert(Int,x) +convert(::Type{Signed}, x::Uint8 ) = convert(Int8,x) +convert(::Type{Signed}, x::Uint16 ) = convert(Int16,x) +convert(::Type{Signed}, x::Uint32 ) = convert(Int32,x) convert(::Type{Signed}, x::Uint64 ) = convert(Int64,x) convert(::Type{Signed}, x::Uint128) = convert(Int128,x) convert(::Type{Signed}, x::Float32) = convert(Int,x) convert(::Type{Signed}, x::Float64) = convert(Int,x) convert(::Type{Signed}, x::Char) = convert(Int,x) -convert(::Type{Unsigned}, x::Int8 ) = convert(Uint,x) -convert(::Type{Unsigned}, x::Int16 ) = convert(Uint,x) -convert(::Type{Unsigned}, x::Int32 ) = convert(Uint,x) +convert(::Type{Unsigned}, x::Int8 ) = convert(Uint8,x) +convert(::Type{Unsigned}, x::Int16 ) = convert(Uint16,x) +convert(::Type{Unsigned}, x::Int32 ) = convert(Uint32,x) convert(::Type{Unsigned}, x::Int64 ) = convert(Uint64,x) convert(::Type{Unsigned}, x::Int128 ) = convert(Uint128,x) convert(::Type{Unsigned}, x::Float32) = convert(Uint,x) @@ -396,9 +221,9 @@ const WORD_SIZE = int(Int.size)*8 ## integer promotions ## -promote_rule(::Type{Int16}, ::Type{Int8} ) = Int -promote_rule(::Type{Int32}, ::Type{Int8} ) = Int -promote_rule(::Type{Int32}, ::Type{Int16}) = Int +promote_rule(::Type{Int16}, ::Type{Int8} ) = Int16 +promote_rule(::Type{Int32}, ::Type{Int8} ) = Int32 +promote_rule(::Type{Int32}, ::Type{Int16}) = Int32 promote_rule(::Type{Int64}, ::Type{Int8} ) = Int64 promote_rule(::Type{Int64}, ::Type{Int16}) = Int64 promote_rule(::Type{Int64}, ::Type{Int32}) = Int64 @@ -407,9 +232,9 @@ promote_rule(::Type{Int128}, ::Type{Int16}) = Int128 promote_rule(::Type{Int128}, ::Type{Int32}) = Int128 promote_rule(::Type{Int128}, ::Type{Int64}) = Int128 -promote_rule(::Type{Uint16}, ::Type{Uint8} ) = Uint -promote_rule(::Type{Uint32}, ::Type{Uint8} ) = Uint -promote_rule(::Type{Uint32}, ::Type{Uint16}) = Uint +promote_rule(::Type{Uint16}, ::Type{Uint8} ) = Uint16 +promote_rule(::Type{Uint32}, ::Type{Uint8} ) = Uint32 +promote_rule(::Type{Uint32}, ::Type{Uint16}) = Uint32 promote_rule(::Type{Uint64}, ::Type{Uint8} ) = Uint64 promote_rule(::Type{Uint64}, ::Type{Uint16}) = Uint64 promote_rule(::Type{Uint64}, ::Type{Uint32}) = Uint64 @@ -418,15 +243,15 @@ promote_rule(::Type{Uint128}, ::Type{Uint16}) = Uint128 promote_rule(::Type{Uint128}, ::Type{Uint32}) = Uint128 promote_rule(::Type{Uint128}, ::Type{Uint64}) = Uint128 -promote_rule(::Type{Uint8}, ::Type{Int8} ) = Int -promote_rule(::Type{Uint8}, ::Type{Int16} ) = Int -promote_rule(::Type{Uint8}, ::Type{Int32} ) = Int +promote_rule(::Type{Uint8}, ::Type{Int8} ) = Int8 +promote_rule(::Type{Uint8}, ::Type{Int16} ) = Int16 +promote_rule(::Type{Uint8}, ::Type{Int32} ) = Int32 promote_rule(::Type{Uint8}, ::Type{Int64} ) = Int64 promote_rule(::Type{Uint8}, ::Type{Int128}) = Int128 -promote_rule(::Type{Uint16}, ::Type{Int8} ) = Int -promote_rule(::Type{Uint16}, ::Type{Int16} ) = Int -promote_rule(::Type{Uint16}, ::Type{Int32} ) = Int +promote_rule(::Type{Uint16}, ::Type{Int8} ) = Int16 +promote_rule(::Type{Uint16}, ::Type{Int16} ) = Int16 +promote_rule(::Type{Uint16}, ::Type{Int32} ) = Int32 promote_rule(::Type{Uint16}, ::Type{Int64} ) = Int64 promote_rule(::Type{Uint16}, ::Type{Int128}) = Int128 diff --git a/base/printf.jl b/base/printf.jl index b19483795714b..27d823ac5fbde 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -4,7 +4,7 @@ export @printf, @sprintf ### printf formatter generation ### const SmallFloatingPoint = Union(Float64,Float32,Float16) -const SmallNumber = Union(SmallFloatingPoint,Base.Signed64,Base.Unsigned64,Uint128,Int128) +const SmallNumber = Union(SmallFloatingPoint,Base.SignedUpto128,Base.UnsignedUpto128) function gen(s::String) args = {} diff --git a/base/reducedim.jl b/base/reducedim.jl index 23b0950298174..d595d4838d2fb 100644 --- a/base/reducedim.jl +++ b/base/reducedim.jl @@ -101,9 +101,9 @@ reducedim_init(f, op::OrFun, A::AbstractArray, region) = reducedim_initarray(A, # specialize to make initialization more efficient for common cases -typealias CommonReduceResult Union(Uint64,Uint128,Int64,Int128,Float32,Float64) +typealias CommonReduceResult Union(Int8,Uint8,Int16,Uint16,Int32,Uint32,Uint64,Uint128,Int64,Int128,Float32,Float64) -for (IT, RT) in ((CommonReduceResult, :(eltype(A))), (SmallSigned, :Int), (SmallUnsigned, :Uint)) +for (IT, RT) in ((CommonReduceResult, :(eltype(A))),) T = Union([AbstractArray{t} for t in IT.types]..., [AbstractArray{Complex{t}} for t in IT.types]...) @eval begin reducedim_init(f::IdFun, op::AddFun, A::$T, region) = diff --git a/base/utf16.jl b/base/utf16.jl index 29c496dca7f6e..0c7638e879c20 100644 --- a/base/utf16.jl +++ b/base/utf16.jl @@ -11,7 +11,7 @@ end utf16_is_lead(c::Uint16) = (c & 0xfc00) == 0xd800 utf16_is_trail(c::Uint16) = (c & 0xfc00) == 0xdc00 utf16_is_surrogate(c::Uint16) = (c & 0xf800) == 0xd800 -utf16_get_supplementary(lead::Uint16, trail::Uint16) = char((lead-0xd7f7)<<10 + trail) +utf16_get_supplementary(lead::Uint16, trail::Uint16) = char((int32(lead)-0xd7f7)<<10 + trail) function endof(s::UTF16String) d = s.data diff --git a/test/numbers.jl b/test/numbers.jl index 7e4f8103a4c48..ecabdd295d4fb 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -1341,7 +1341,7 @@ end @test -0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 == -(0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001) -@test isa(-0x00,Uint) +@test isa(-0x00,Uint8) @test isa(-0x0000000000000000,Uint64) @test isa(-0x00000000000000000,Uint128) @test isa(-0x00000000000000000000000000000000,Uint128) diff --git a/test/reduce.jl b/test/reduce.jl index 1799cc9176d39..dbbd94b652d8b 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -22,7 +22,7 @@ # sum -@test sum(Int8[]) === 0 +@test sum(Int8[]) === int8(0) @test sum(Int[]) === 0 @test sum(Float64[]) === 0.0 @@ -30,7 +30,7 @@ @test sum(3) === 3 @test sum(3.0) === 3.0 -@test sum([int8(3)]) === 3 +@test sum([int8(3)]) === int8(3) @test sum([3]) === 3 @test sum([3.0]) === 3.0 @@ -49,14 +49,14 @@ fz = float(z) a = randn(32) # need >16 elements to trigger BLAS code path b = complex(randn(32), randn(32)) @test sumabs(Float64[]) === 0.0 -@test sumabs([int8(-2)]) === 2 +@test sumabs([int8(-2)]) === int8(2) @test sumabs(z) === 14 @test sumabs(fz) === 14.0 @test_approx_eq sumabs(a) sum(abs(a)) @test_approx_eq sumabs(b) sum(abs(b)) @test sumabs2(Float64[]) === 0.0 -@test sumabs2([int8(-2)]) === 4 +@test sumabs2([int8(-2)]) === int8(4) @test sumabs2(z) === 54 @test sumabs2(fz) === 54.0 @test_approx_eq sumabs2(a) sum(abs2(a)) @@ -91,11 +91,11 @@ end # prod prod(Int[]) === 0 -prod(Int8[]) === 0 +prod(Int8[]) === int8(0) prod(Float64[]) === 0.0 prod([3]) === 0 -prod([int8(3)]) === 0 +prod([int8(3)]) === int8(0) prod([3.0]) === 0.0 prod(z) === 120 @@ -105,8 +105,8 @@ prod(fz) === 120.0 prod2(itr) = invoke(prod, (Any,), itr) @test prod(Int[]) === prod2(Int[]) === 1 @test prod(Int[7]) === prod2(Int[7]) === 7 -@test typeof(prod(Int8[])) == typeof(prod(Int8[1])) == typeof(prod(Int8[1, 7])) == Int -@test typeof(prod2(Int8[])) == typeof(prod2(Int8[1])) == typeof(prod2(Int8[1 7])) == Int +@test typeof(prod(Int8[])) == typeof(prod(Int8[1])) == typeof(prod(Int8[1, 7])) == Int8 +@test typeof(prod2(Int8[])) == typeof(prod2(Int8[1])) == typeof(prod2(Int8[1 7])) == Int8 # maximum & minimum & extrema