Skip to content

Commit

Permalink
Compare with Uint64 values correctly.
Browse files Browse the repository at this point in the history
Previously `-1 < typemax(Uint64)` was false.
  • Loading branch information
StefanKarpinski committed Dec 25, 2011
1 parent dd501da commit 6b7ede3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
21 changes: 20 additions & 1 deletion j/int.j
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ convert(::Type{Unsigned}, x::Bool ) = convert(Uint8, 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) # LOSSY
convert(::Type{Unsigned}, x::Int64 ) = convert(Uint64, x)
convert(::Type{Unsigned}, x::Float32) = convert(Uint32, x)
convert(::Type{Unsigned}, x::Float64) = convert(Uint64, x)

Expand Down Expand Up @@ -392,6 +392,25 @@ trailing_zeros(x::Uint64) = boxui64(cttz_int(unbox64(x)))
<=(x::Uint32, y::Uint32) = ule_int(unbox32(x),unbox32(y))
<=(x::Uint64, y::Uint64) = ule_int(unbox64(x),unbox64(y))

# this would be unncessary if we had Signed:
==(x::Unsigned, y::Uint64) = uint64(x) == y
==(x::Uint64, y::Unsigned) = x == uint64(y)
!=(x::Unsigned, y::Uint64) = uint64(x) != y
!=(x::Uint64, y::Unsigned) = x != uint64(y)
< (x::Unsigned, y::Uint64) = uint64(x) < y
< (x::Uint64, y::Unsigned) = x < uint64(y)
<=(x::Unsigned, y::Uint64) = uint64(x) <= y
<=(x::Uint64, y::Unsigned) = x <= uint64(y)

==(x::Integer, y::Uint64) = x < 0 ? false : uint64(x) == y
==(x::Uint64, y::Integer) = y < 0 ? false : x == uint64(y)
!=(x::Integer, y::Uint64) = x < 0 ? true : uint64(x) != y
!=(x::Uint64, y::Integer) = y < 0 ? true : x != uint64(y)
< (x::Integer, y::Uint64) = x < 0 ? true : uint64(x) < y
< (x::Uint64, y::Integer) = y <= 0 ? false : x < uint64(y)
<=(x::Integer, y::Uint64) = x <= 0 ? true : uint64(x) <= y
<=(x::Uint64, y::Integer) = y < 0 ? false : x <= uint64(y)

## traits ##

typemin(::Type{Int8 }) = int8(-128)
Expand Down
16 changes: 8 additions & 8 deletions j/operators.j
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ isequal(x::Number, y::Number) = hash(x)==hash(y) && x==y
<=(x,y) = !(y < x)
>=(x,y) = y <= x

max(x, y) = x > y ? x : y
min(x, y) = x < y ? x : y
max(x,y) = x > y ? x : y
min(x,y) = x < y ? x : y

## definitions providing basic traits of arithmetic operators ##

Expand Down Expand Up @@ -84,12 +84,12 @@ mod1{T<:Real}(x::T, y::T) = y-mod(y-x,y)
cmp{T<:Real}(x::T, y::T) = sign(x-y)

# transposed multiply
aCb(a, b) = ctranspose(a)*b
abC(a, b) = a*ctranspose(b)
aCbC(a, b) = ctranspose(a)*ctranspose(b)
aTb(a, b) = transpose(a)*b
abT(a, b) = a*transpose(b)
aTbT(a, b) = transpose(a)*transpose(b)
aCb (a,b) = ctranspose(a)*b
abC (a,b) = a*ctranspose(b)
aCbC(a,b) = ctranspose(a)*ctranspose(b)
aTb (a,b) = transpose(a)*b
abT (a,b) = a*transpose(b)
aTbT(a,b) = transpose(a)*transpose(b)

oftype{T}(::Type{T},c) = convert(T,c)
oftype{T}(x::T,c) = convert(T,c)
Expand Down
4 changes: 2 additions & 2 deletions j/promotion.j
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ end
|(x::Integer, y::Integer) = |(promote(x,y)...)
($)(x::Integer, y::Integer) = ($)(promote(x,y)...)

==(x::Number, y::Number) = (==)(promote(x,y)...)
< (x::Real, y::Real) = (< )(promote(x,y)...)
<=(x::Real, y::Real) = (<=)(promote(x,y)...)
==(x::Number, y::Number) = (==)(promote(x,y)...)

div(x::Real, y::Real) = div(promote(x,y)...)
fld(x::Real, y::Real) = fld(promote(x,y)...)
Expand All @@ -72,5 +72,5 @@ no_op_err(name, T) = error(name," not defined for ",T)
|{T<:Integer}(x::T, y::T) = no_op_err("|", T)
($){T<:Integer}(x::T, y::T) = no_op_err("\$", T)
<{T<:Real}(x::T, y::T) = no_op_err("<", T)
=={T<:Number}(x::T, y::T) = no_op_err("==", T)
<{T<:Real}(x::T, y::T) = no_op_err("<", T)
8 changes: 8 additions & 0 deletions test/core.j
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ end
@assert (ComplexPair(1,2)/ComplexPair(2.5,3.0))*ComplexPair(2.5,3.0) == ComplexPair(1,2)
@assert 0.7 < real(sqrt(ComplexPair(0,1))) < 0.707107
for S = {Int8, Int16, Int32, Int64},
U = {Uint8, Uint16, Uint32, Uint64}
@assert !(-one(S) == typemax(U))
@assert -one(S) != typemax(U)
@assert -one(S) < typemax(U)
@assert !(typemax(U) <= -one(S))
end
# check type of constructed rationals
int_types = {Int8, Uint8, Int16, Uint16, Int32, Uint32, Int64, Uint64}
for N = int_types, D = int_types
Expand Down

0 comments on commit 6b7ede3

Please sign in to comment.