diff --git a/base/dates/types.jl b/base/dates/types.jl index 4cde4ca353af7..b1e5e437f2dd0 100644 --- a/base/dates/types.jl +++ b/base/dates/types.jl @@ -160,4 +160,4 @@ Base.promote_rule(::Type{Date},x::Type{DateTime}) = DateTime Base.isless(x::Date,y::Date) = isless(value(x),value(y)) Base.isless(x::DateTime,y::DateTime) = isless(value(x),value(y)) Base.isless(x::TimeType,y::TimeType) = isless(promote(x,y)...) -==(x::TimeType,y::TimeType) = ===(promote(x,y)...) \ No newline at end of file +==(x::TimeType,y::TimeType) = ===(promote(x,y)...) diff --git a/base/int.jl b/base/int.jl index 85760b852cd2d..58382165d7b7e 100644 --- a/base/int.jl +++ b/base/int.jl @@ -43,6 +43,11 @@ abs(x::Signed) = flipsign(x,x) ~(n::Integer) = -n-1 +asunsigned(x::Integer) = reinterpret(typeof(unsigned(zero(x))), x) +asunsigned(x) = unsigned(x) +assigned(x::Integer) = reinterpret(typeof(signed(zero(x))), x) +assigned(x) = signed(x) + div(x::Signed, y::Unsigned) = flipsign(assigned(div(asunsigned(abs(x)),y)),x) div(x::Unsigned, y::Signed) = asunsigned(flipsign(assigned(div(x,asunsigned(abs(y)))),y)) @@ -132,9 +137,6 @@ for T in IntTypes end end -asunsigned(x) = reinterpret(typeof(unsigned(zero(x))), x) -assigned(x) = reinterpret(typeof(signed(zero(x))), x) - ==(x::Signed, y::Unsigned) = (x >= 0) & (asunsigned(x) == y) ==(x::Unsigned, y::Signed ) = (y >= 0) & (x == asunsigned(y)) < (x::Signed, y::Unsigned) = (x < 0) | (asunsigned(x) < y) @@ -227,7 +229,8 @@ int32(x) = convert(Int32,x) int64(x) = convert(Int64,x) int128(x) = convert(Int128,x) -uint8(x) = itrunc(Uint8,x) +uint8(x) = convert(Uint8, x) +uint8(x::Integer) = itrunc(Uint8,x) uint8(x::Int8) = box(Uint8,unbox(Int8,x)) uint16(x) = convert(Uint16,x) uint32(x) = convert(Uint32,x) diff --git a/base/range.jl b/base/range.jl index 6979e3575ffa2..dcda238d4d07f 100644 --- a/base/range.jl +++ b/base/range.jl @@ -39,9 +39,9 @@ immutable StepRange{T,S} <: OrdinalRange{T,S} if T<:Signed && (diff > zero(diff)) != (stop > start) # handle overflowed subtraction with unsigned rem if diff > zero(diff) - remain = -oftype(T, unsigned(-diff) % step) + remain = -oftype(T, asunsigned(-diff) % step) else - remain = oftype(T, unsigned(diff) % step) + remain = oftype(T, asunsigned(diff) % step) end else remain = steprem(start,stop,step) diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index 8f0b0b22b25c9..1a135cfee02a0 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -424,6 +424,9 @@ static Value *generic_box(jl_value_t *targ, jl_value_t *x, jl_codectx_t *ctx) if (vxt != llvmt) { if (vxt == T_void) return vx; + if (!vxt->isSingleValueType()) { + jl_error("box: argument not of a primitive type"); + } if (llvmt == T_int1) { vx = builder.CreateTrunc(vx, llvmt); } diff --git a/test/dates/types.jl b/test/dates/types.jl index c9edf562fce30..ea7e71f0ffaaa 100644 --- a/test/dates/types.jl +++ b/test/dates/types.jl @@ -63,9 +63,9 @@ test = Dates.Date(1,1,1) @test Dates.Date(false,true,true) == test - Dates.Year(1) @test_throws ArgumentError Dates.Date(true,true,false) @test Dates.Date(uint64(1),uint64(1),uint64(1)) == test -@test Dates.Date(0xffffffffffffffff,uint64(1),uint64(1)) == test - Dates.Year(2) +@test Dates.Date(-1,uint64(1),uint64(1)) == test - Dates.Year(2) @test Dates.Date(int128(1),int128(1),int128(1)) == test -@test Dates.Date(170141183460469231731687303715884105727,int128(1),int128(1)) == test - Dates.Year(2) +@test_throws InexactError Dates.Date(170141183460469231731687303715884105727,int128(1),int128(1)) @test Dates.Date(uint128(1),uint128(1),uint128(1)) == test @test Dates.Date(big(1),big(1),big(1)) == test @test Dates.Date(big(1),big(1),big(1)) == test @@ -171,4 +171,4 @@ ms = Dates.Millisecond(1) @test Dates.Date(d,y) == Dates.Date(1,1,1) @test Dates.Date(d,m) == Dates.Date(1,1,1) @test Dates.Date(m,y) == Dates.Date(1,1,1) -=# \ No newline at end of file +=#