diff --git a/base/arraymath.jl b/base/arraymath.jl index f6009bd7a89c83..22a6c6db6f17d9 100644 --- a/base/arraymath.jl +++ b/base/arraymath.jl @@ -66,7 +66,7 @@ promote_array_type{S<:Integer}(::typeof(./), ::Type{S}, ::Type{Bool}, T::Type) = promote_array_type{S<:Integer}(::typeof(.\), ::Type{S}, ::Type{Bool}, T::Type) = T promote_array_type{S<:Integer}(F, ::Type{S}, ::Type{Bool}, T::Type) = T -for f in (:+, :-, :div, :mod, :&, :|, :$) +for f in (:+, :-, :div, :mod, :&, :|, :xor) @eval ($f)(A::AbstractArray, B::AbstractArray) = _elementwise($f, promote_eltype_op($f, A, B), A, B) end @@ -89,7 +89,7 @@ function _elementwise{T}(op, ::Type{T}, A::AbstractArray, B::AbstractArray) return F end -for f in (:.+, :.-, :.*, :./, :.\, :.^, :.÷, :.%, :.<<, :.>>, :div, :mod, :rem, :&, :|, :$) +for f in (:.+, :.-, :.*, :./, :.\, :.^, :.÷, :.%, :.<<, :.>>, :div, :mod, :rem, :&, :|, :xor) @eval begin function ($f){T}(A::Number, B::AbstractArray{T}) R = promote_op($f, typeof(A), T) diff --git a/base/associative.jl b/base/associative.jl index 5de0864871215a..67d2944215b7b5 100644 --- a/base/associative.jl +++ b/base/associative.jl @@ -251,7 +251,7 @@ const hasha_seed = UInt === UInt64 ? 0x6d35bb51952d5539 : 0x952d5539 function hash(a::Associative, h::UInt) h = hash(hasha_seed, h) for (k,v) in a - h $= hash(k, hash(v)) + h = xor(h, hash(k, hash(v))) end return h end diff --git a/base/bitarray.jl b/base/bitarray.jl index 34ef888850b20b..3c66f16cc4e203 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1333,12 +1333,12 @@ function (|)(B::BitArray, x::Bool) end (|)(x::Bool, B::BitArray) = B | x -function ($)(B::BitArray, x::Bool) +function xor(B::BitArray, x::Bool) x ? ~B : copy(B) end -($)(x::Bool, B::BitArray) = B $ x +xor(x::Bool, B::BitArray) = xor(B, x) -for f in (:&, :|, :$) +for f in (:&, :|, :xor) @eval begin function ($f)(A::BitArray, B::BitArray) F = BitArray(promote_shape(size(A),size(B))...) @@ -2006,10 +2006,10 @@ map!(::typeof(identity), dest::BitArray, A::BitArray) = copy!(dest, A) for (T, f) in ((:(Union{typeof(&), typeof(*), typeof(min)}), :(&)), (:(Union{typeof(|), typeof(max)}), :(|)), - (:(Union{typeof($), typeof(!=)}), :($)), + (:(Union{typeof(xor), typeof(!=)}), :xor), (:(Union{typeof(>=), typeof(^)}), :((p, q) -> p | ~q)), (:(typeof(<=)), :((p, q) -> ~p | q)), - (:(typeof(==)), :((p, q) -> ~(p $ q))), + (:(typeof(==)), :((p, q) -> ~xor(p, q))), (:(typeof(<)), :((p, q) -> ~p & q)), (:(typeof(>)), :((p, q) -> p & ~q))) @eval map(::$T, A::BitArray, B::BitArray) = bit_map!($f, similar(A), A, B) @@ -2058,12 +2058,12 @@ transpose(B::BitVector) = reshape(copy(B), 1, length(B)) # http://www.hackersdelight.org/hdcodetxt/transpose8.c.txt function transpose8x8(x::UInt64) y = x - t = (y $ (y >>> 7)) & 0x00aa00aa00aa00aa - y = y $ t $ (t << 7) - t = (y $ (y >>> 14)) & 0x0000cccc0000cccc - y = y $ t $ (t << 14) - t = (y $ (y >>> 28)) & 0x00000000f0f0f0f0 - return y $ t $ (t << 28) + t = xor(y, y >>> 7) & 0x00aa00aa00aa00aa + y = xor(y, t, t << 7) + t = xor(y, y >>> 14) & 0x0000cccc0000cccc + y = xor(y, t, t << 14) + t = xor(y, y >>> 28) & 0x00000000f0f0f0f0 + return xor(y, t, t << 28) end function form_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, m::Int, cgap::Int, cinc::Int, nc::Int, msk8::UInt64) diff --git a/base/bool.jl b/base/bool.jl index 82bbf4ec9ec8b2..8a524dbb0d29e3 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -23,7 +23,7 @@ end (~)(x::Bool) = !x (&)(x::Bool, y::Bool) = box(Bool,and_int(unbox(Bool,x),unbox(Bool,y))) (|)(x::Bool, y::Bool) = box(Bool,or_int(unbox(Bool,x),unbox(Bool,y))) -($)(x::Bool, y::Bool) = (x!=y) +xor(x::Bool, y::Bool) = (x!=y) >>(x::Bool, c::Unsigned) = Int(x) >> c <<(x::Bool, c::Unsigned) = Int(x) << c diff --git a/base/broadcast.jl b/base/broadcast.jl index fed4d06071336a..0049341038b10f 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -498,9 +498,9 @@ function broadcast_bitarrays(scalarf, bitf, A::AbstractArray{Bool}, B::AbstractA return F end -biteq(a::UInt64, b::UInt64) = ~a $ b +biteq(a::UInt64, b::UInt64) = xor(~a, b) bitlt(a::UInt64, b::UInt64) = ~a & b -bitneq(a::UInt64, b::UInt64) = a $ b +bitneq(a::UInt64, b::UInt64) = xor(a, b) bitle(a::UInt64, b::UInt64) = ~a | b .==(A::AbstractArray{Bool}, B::AbstractArray{Bool}) = broadcast_bitarrays(==, biteq, A, B) diff --git a/base/c.jl b/base/c.jl index 09367b9709cc50..9b50629ffdec88 100644 --- a/base/c.jl +++ b/base/c.jl @@ -187,24 +187,24 @@ function transcode(::Type{UInt16}, src::Vector{UInt8}) push!(dst, a) a = b; continue elseif a < 0xe0 # 2-byte UTF-8 - push!(dst, 0x3080 $ (UInt16(a) << 6) $ b) + push!(dst, xor(0x3080, UInt16(a) << 6, b)) elseif i < n # 3/4-byte character c = src[i += 1] if -64 <= (c % Int8) # invalid UTF-8 (non-continuation) push!(dst, a, b) a = c; continue elseif a < 0xf0 # 3-byte UTF-8 - push!(dst, 0x2080 $ (UInt16(a) << 12) $ (UInt16(b) << 6) $ c) + push!(dst, xor(0x2080, UInt16(a) << 12, UInt16(b) << 6, c)) elseif i < n d = src[i += 1] if -64 <= (d % Int8) # invalid UTF-8 (non-continuation) push!(dst, a, b, c) a = d; continue elseif a == 0xf0 && b < 0x90 # overlong encoding - push!(dst, 0x2080 $ (UInt16(b) << 12) $ (UInt16(c) << 6) $ d) + push!(dst, xor(0x2080, UInt16(b) << 12, UInt16(c) << 6, d)) else # 4-byte UTF-8 push!(dst, 0xe5b8 + (UInt16(a) << 8) + (UInt16(b) << 2) + (c >> 4), - 0xdc80 $ (UInt16(c & 0xf) << 6) $ d) + xor(0xdc80, UInt16(c & 0xf) << 6, d)) end else # too short push!(dst, a, b, c) @@ -273,7 +273,7 @@ function transcode(::Type{UInt8}, src::Vector{UInt16}) a += 0x2840 dst[j += 1] = 0xf0 | ((a >> 8) % UInt8) dst[j += 1] = 0x80 | ((a % UInt8) >> 2) - dst[j += 1] = 0xf0 $ ((((a % UInt8) << 4) & 0x3f) $ (b >> 6) % UInt8) + dst[j += 1] = xor(0xf0, ((a % UInt8) << 4) & 0x3f, (b >> 6) % UInt8) dst[j += 1] = 0x80 | ((b % UInt8) & 0x3f) else dst[j += 1] = 0xe0 | ((a >> 12) % UInt8) diff --git a/base/char.jl b/base/char.jl index 58481c6d39c2a1..82c88cdd88a695 100644 --- a/base/char.jl +++ b/base/char.jl @@ -33,7 +33,7 @@ in(x::Char, y::Char) = x == y isless(x::Char, y::Char) = UInt32(x) < UInt32(y) const hashchar_seed = 0xd4d64234 -hash(x::Char, h::UInt) = hash_uint64(((UInt64(x)+hashchar_seed)<<32) $ UInt64(h)) +hash(x::Char, h::UInt) = hash_uint64(xor((UInt64(x)+hashchar_seed)<<32, UInt64(h))) -(x::Char, y::Char) = Int(x) - Int(y) -(x::Char, y::Integer) = Char(Int32(x) - Int32(y)) diff --git a/base/combinatorics.jl b/base/combinatorics.jl index cac4b04c3fa9bb..103dc68a891440 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -73,7 +73,7 @@ function isperm(A) n = length(A) used = falses(n) for a in A - (0 < a <= n) && (used[a] $= true) || return false + (0 < a <= n) && (used[a] = xor(used[a], true)) || return false end true end diff --git a/base/complex.jl b/base/complex.jl index 161bff0743611e..095ab8342cab82 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -162,7 +162,7 @@ const hash_0_imag = hash(0, h_imag) function hash(z::Complex, h::UInt) # TODO: with default argument specialization, this would be better: # hash(real(z), h $ hash(imag(z), h $ h_imag) $ hash(0, h $ h_imag)) - hash(real(z), h $ hash(imag(z), h_imag) $ hash_0_imag) + hash(real(z), xor(h, hash(imag(z), h_imag), hash_0_imag)) end ## generic functions of complex numbers ## diff --git a/base/dSFMT.jl b/base/dSFMT.jl index b0eb6e7d410896..c65c699a5c3469 100644 --- a/base/dSFMT.jl +++ b/base/dSFMT.jl @@ -115,19 +115,19 @@ function dsfmt_jump_add!(dest::Vector{UInt64}, src::Vector{UInt64}) while i <= N-diff j = i*2-1 p = j + diff*2 - dest[j] $= src[p] - dest[j+1] $= src[p+1] + dest[j] = xor(dest[j], src[p]) + dest[j+1] = xor(dest[j+1], src[p+1]) i += 1 end while i <= N j = i*2-1 p = j + (diff - N)*2 - dest[j] $= src[p] - dest[j+1] $= src[p+1] + dest[j] = xor(dest[j], src[p]) + dest[j+1] = xor(dest[j+1], src[p+1]) i += 1 end - dest[N*2+1] $= src[N*2+1] - dest[N*2+2] $= src[N*2+2] + dest[N*2+1] = xor(dest[N*2+1], src[N*2+1]) + dest[N*2+2] = xor(dest[N*2+2], src[N*2+2]) return dest end @@ -148,10 +148,10 @@ function dsfmt_jump_next_state!(mts::Vector{UInt64}) t1 = mts[a+1] L0 = mts[u] L1 = mts[u+1] - mts[u] = (t0 << SL1) $ (L1 >> 32) $ (L1 << 32) $ mts[b] - mts[u+1] = (t1 << SL1) $ (L0 >> 32) $ (L0 << 32) $ mts[b+1] - mts[a] = (mts[u] >> SR) $ (mts[u] & MSK1) $ t0 - mts[a+1] = (mts[u+1] >> SR) $ (mts[u+1] & MSK2) $ t1 + mts[u] = xor(t0 << SL1, L1 >> 32, L1 << 32, mts[b]) + mts[u+1] = xor(t1 << SL1, L0 >> 32, L0 << 32, mts[b+1]) + mts[a] = xor(mts[u] >> SR, mts[u] & MSK1, t0) + mts[a+1] = xor(mts[u+1] >> SR, mts[u+1] & MSK2, t1) mts[end] = (mts[end] + 2) % (N*2) return mts diff --git a/base/deprecated.jl b/base/deprecated.jl index 3b9dec571d90e7..c0a2410dfbfcfb 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -303,7 +303,7 @@ for (Fun, func) in [(:IdFun, :identity), (:ConjFun, :conj), (:AndFun, :&), (:OrFun, :|), - (:XorFun, :$), + (:XorFun, :xor), (:AddFun, :+), (:DotAddFun, :.+), (:SubFun, :-), @@ -1022,6 +1022,9 @@ end)) @deprecate ipermutedims(A::AbstractArray,p) permutedims(A, invperm(p)) +# 18696 +@deprecate ($) xor + @deprecate is (===) diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index 2b75cedb08b38c..740f1bce56b256 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -3354,8 +3354,8 @@ Compute the Dawson function (scaled imaginary error function) of `x`, defined by dawson """ - \$(x, y) + xor(x, y) Bitwise exclusive or. """ -Base.:$(x, y) +Base.xor(x, y) diff --git a/base/exports.jl b/base/exports.jl index 6cdaf50c3bf3ca..75a4b36c41836e 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -205,7 +205,7 @@ export !==, ≡, ≢, - $, + xor, %, ÷, &, diff --git a/base/fastmath.jl b/base/fastmath.jl index fd2edceb0befd4..93dd88f3c9ec7a 100644 --- a/base/fastmath.jl +++ b/base/fastmath.jl @@ -153,7 +153,7 @@ mul_fast{T<:FloatTypes}(x::T, y::T, zs::T...) = cmp_fast{T<:FloatTypes}(x::T, y::T) = ifelse(x==y, 0, ifelse(x 0) $ (y > 0), r+y, r) + ifelse(xor(r > 0, y > 0), r+y, r) end end diff --git a/base/float.jl b/base/float.jl index 99490d8bdcd45e..4191bd29d6c608 100644 --- a/base/float.jl +++ b/base/float.jl @@ -361,7 +361,7 @@ _default_type(T::Union{Type{Real},Type{AbstractFloat}}) = Float64 ## floating point arithmetic ## -(x::Float64) = box(Float64,neg_float(unbox(Float64,x))) -(x::Float32) = box(Float32,neg_float(unbox(Float32,x))) --(x::Float16) = reinterpret(Float16, reinterpret(UInt16,x) $ 0x8000) +-(x::Float16) = reinterpret(Float16, xor(reinterpret(UInt16,x), 0x8000)) for op in (:+,:-,:*,:/,:\,:^) @eval ($op)(a::Float16, b::Float16) = Float16(($op)(Float32(a), Float32(b))) @@ -400,7 +400,7 @@ function mod{T<:AbstractFloat}(x::T, y::T) r = rem(x,y) if r == 0 copysign(r,y) - elseif (r > 0) $ (y > 0) + elseif xor(r > 0, y > 0) r+y else r @@ -531,7 +531,7 @@ const hx_NaN = hx(UInt64(0), NaN, UInt(0 )) hash(x::UInt64, h::UInt) = hx(x, Float64(x), h) hash(x::Int64, h::UInt) = hx(reinterpret(UInt64,abs(x)), Float64(x), h) -hash(x::Float64, h::UInt) = isnan(x) ? (hx_NaN $ h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h) +hash(x::Float64, h::UInt) = isnan(x) ? xor(hx_NaN, h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h) hash(x::Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h) hash(x::Float32, h::UInt) = hash(Float64(x), h) @@ -577,7 +577,7 @@ function nextfloat(f::Union{Float16,Float32,Float64}, d::Integer) fu = fumax else du = da % U - if fneg $ dneg + if xor(fneg, dneg) if du > fu fu = min(fumax, du - fu) fneg = !fneg diff --git a/base/gmp.jl b/base/gmp.jl index bf0111598e5b08..1d0deb3f8b35d9 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -4,7 +4,7 @@ module GMP export BigInt -import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), ($), +import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor, binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, powermod, sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal, @@ -194,7 +194,7 @@ function convert{T<:Signed}(::Type{T}, x::BigInt) else 0 <= n <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError()) y = x % T - (x.size > 0) $ (y > 0) && throw(InexactError()) # catch overflow + xor(x.size > 0, y > 0) && throw(InexactError()) # catch overflow y end end @@ -249,7 +249,7 @@ promote_rule{T<:Integer}(::Type{BigInt}, ::Type{T}) = BigInt for (fJ, fC) in ((:+, :add), (:-,:sub), (:*, :mul), (:fld, :fdiv_q), (:div, :tdiv_q), (:mod, :fdiv_r), (:rem, :tdiv_r), (:gcd, :gcd), (:lcm, :lcm), - (:&, :and), (:|, :ior), (:$, :xor)) + (:&, :and), (:|, :ior), (:xor, :xor)) @eval begin function ($fJ)(x::BigInt, y::BigInt) z = BigInt() @@ -279,7 +279,7 @@ function invmod(x::BigInt, y::BigInt) end # More efficient commutative operations -for (fJ, fC) in ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:$, :xor)) +for (fJ, fC) in ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:xor, :xor)) @eval begin function ($fJ)(a::BigInt, b::BigInt, c::BigInt) z = BigInt() diff --git a/base/hashing.jl b/base/hashing.jl index ab7ed4631b3def..0cda93a3f5ecd0 100644 --- a/base/hashing.jl +++ b/base/hashing.jl @@ -14,11 +14,11 @@ hash(x::ANY, h::UInt) = 3*object_id(x) - h function hash_64_64(n::UInt64) local a::UInt64 = n a = ~a + a << 21 - a = a $ a >> 24 + a = xor(a, a >> 24) a = a + a << 3 + a << 8 - a = a $ a >> 14 + a = xor(a, a >> 14) a = a + a << 2 + a << 4 - a = a $ a >> 28 + a = xor(a, a >> 28) a = a + a << 31 return a end @@ -26,22 +26,22 @@ end function hash_64_32(n::UInt64) local a::UInt64 = n a = ~a + a << 18 - a = a $ a >> 31 + a = xor(a, a >> 31) a = a * 21 - a = a $ a >> 11 + a = xor(a, a >> 11) a = a + a << 6 - a = a $ a >> 22 + a = xor(a, a >> 22) return a % UInt32 end function hash_32_32(n::UInt32) local a::UInt32 = n a = a + 0x7ed55d16 + a << 12 - a = a $ 0xc761c23c $ a >> 19 + a = xor(a, 0xc761c23c, a >> 19) a = a + 0x165667b1 + a << 5 - a = a + 0xd3a2646c $ a << 9 + a = a + xor(0xd3a2646c, a << 9) a = a + 0xfd7046c5 + a << 3 - a = a $ 0xb55a4f09 $ a >> 16 + a = xor(a, 0xb55a4f09, a >> 16) return a end diff --git a/base/hashing2.jl b/base/hashing2.jl index 3d29fcef204c5c..35ba3a45909341 100644 --- a/base/hashing2.jl +++ b/base/hashing2.jl @@ -3,11 +3,11 @@ ## efficient value-based hashing of integers ## function hash_integer(n::Integer, h::UInt) - h = hash_uint((n % UInt) $ h) $ h + h = xor(hash_uint(xor(n % UInt, h)), h) n = abs(n) n >>>= sizeof(UInt) << 3 while n != 0 - h = hash_uint((n % UInt) $ h) $ h + h = xor(hash_uint(xor(n % UInt, h)), h) n >>>= sizeof(UInt) << 3 end return h @@ -18,9 +18,9 @@ function hash_integer(n::BigInt, h::UInt) s == 0 && return hash_integer(0, h) p = convert(Ptr{UInt}, n.d) b = unsafe_load(p) - h = hash_uint(ifelse(s < 0, -b, b) $ h) $ h + h = xor(hash_uint(xor(ifelse(s < 0, -b, b), h)), h) for k = 2:abs(s) - h = hash_uint(unsafe_load(p, k) $ h) $ h + h = xor(hash_uint(xor(unsafe_load(p, k), h)), h) end return h end diff --git a/base/int.jl b/base/int.jl index 33836165e1ca06..3d069c8fb81ef7 100644 --- a/base/int.jl +++ b/base/int.jl @@ -76,7 +76,7 @@ flipsign(x::Signed, y::Float32) = flipsign(x, reinterpret(Int32,y)) flipsign(x::Signed, y::Float64) = flipsign(x, reinterpret(Int64,y)) flipsign(x::Signed, y::Real) = flipsign(x, -oftype(x,signbit(y))) -copysign(x::Signed, y::Signed) = flipsign(x, x$y) +copysign(x::Signed, y::Signed) = flipsign(x, xor(x,y)) copysign(x::Signed, y::Float16) = copysign(x, reinterpret(Int16,y)) copysign(x::Signed, y::Float32) = copysign(x, reinterpret(Int32,y)) copysign(x::Signed, y::Float64) = copysign(x, reinterpret(Int64,y)) @@ -149,7 +149,7 @@ rem{T<:BitUnsigned64}(x::T, y::T) = box(T,checked_urem_int(unbox(T,x),unbox(T,y) fld{T<:Unsigned}(x::T, y::T) = div(x,y) function fld{T<:Integer}(x::T, y::T) d = div(x,y) - d - (signbit(x$y) & (d*y!=x)) + d - (signbit(xor(x,y)) & (d*y!=x)) end # cld(x,y) = div(x,y) + ((x>0) == (y>0) && rem(x,y) != 0 ? 1 : 0) @@ -167,7 +167,7 @@ end (~){T<:BitInteger}(x::T) = box(T,not_int(unbox(T,x))) (&){T<:BitInteger}(x::T, y::T) = box(T,and_int(unbox(T,x),unbox(T,y))) (|){T<:BitInteger}(x::T, y::T) = box(T, or_int(unbox(T,x),unbox(T,y))) -($){T<:BitInteger}(x::T, y::T) = box(T,xor_int(unbox(T,x),unbox(T,y))) +xor{T<:BitInteger}(x::T, y::T) = box(T,xor_int(unbox(T,x),unbox(T,y))) bswap{T<:Union{Int8,UInt8}}(x::T) = x bswap{T<:Union{Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128}}(x::T) = diff --git a/base/intset.jl b/base/intset.jl index b512faa9bfcf4d..22703a665483b3 100644 --- a/base/intset.jl +++ b/base/intset.jl @@ -140,7 +140,7 @@ function symdiff!(s::IntSet, n::Integer) elseif n < 0 throw(ArgumentError("IntSet elements cannot be negative")) end - s.bits[n>>5 + 1] $= (UInt32(1)<<(n&31)) + s.bits[n>>5 + 1] = xor(s.bits[n>>5 + 1], UInt32(1)<<(n&31)) return s end @@ -282,14 +282,14 @@ function symdiff!(s::IntSet, s2::IntSet) end lim = length(s2.bits) for n = 1:lim - s.bits[n] $= s2.bits[n] + s.bits[n] = xor(s.bits[n], s2.bits[n]) end if s2.fill1s for n=lim+1:length(s.bits) s.bits[n] = ~s.bits[n] end end - s.fill1s $= s2.fill1s + s.fill1s = xor(s.fill1s, s2.fill1s) s end diff --git a/base/math.jl b/base/math.jl index 6df96f53d03c52..335b829ff34b71 100644 --- a/base/math.jl +++ b/base/math.jl @@ -393,10 +393,10 @@ function significand{T<:AbstractFloat}(x::T) if xe == 0 # x is subnormal x == 0 && return x xs = xu & sign_mask(T) - xu $= xs + xu = xor(xu, xs) m = leading_zeros(xu)-exponent_bits(T) xu <<= m - xu $= xs + xu = xor(xu, xs) elseif xe == exponent_mask(T) # NaN or Inf return x end @@ -419,7 +419,7 @@ function frexp{T<:AbstractFloat}(x::T) xs == 0 && return x, 0 # +-0 m = unsigned(leading_zeros(xs) - exponent_bits(T)) xs <<= m - xu = xs $ (xu & sign_mask(T)) + xu = xor(xs, (xu & sign_mask(T))) k = 1 - signed(m) end k -= (exponent_bias(T) - 1) diff --git a/base/operators.jl b/base/operators.jl index 8ab8138714fc8c..3ff0583c29131c 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -265,7 +265,7 @@ identity(x) = x *(x::Number) = x (&)(x::Integer) = x (|)(x::Integer) = x -($)(x::Integer) = x +xor(x::Integer) = x # foldl for argument lists. expand recursively up to a point, then # switch to a loop. this allows small cases like `a+b+c+d` to be inlined @@ -279,7 +279,7 @@ function afoldl(op,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,qs...) y end -for op in (:+, :*, :&, :|, :$, :min, :max, :kron) +for op in (:+, :*, :&, :|, :xor, :min, :max, :kron) @eval begin # note: these definitions must not cause a dispatch loop when +(a,b) is # not defined, and must only try to call 2-argument definitions, so @@ -982,7 +982,7 @@ export !=, !==, ===, - $, + xor, %, .%, ÷, @@ -1051,7 +1051,7 @@ export transpose, ctranspose -import ..this_module: !, !=, $, %, .%, ÷, .÷, &, *, +, -, .!=, .+, .-, .*, ./, .<, .<=, .==, .>, +import ..this_module: !, !=, xor, %, .%, ÷, .÷, &, *, +, -, .!=, .+, .-, .*, ./, .<, .<=, .==, .>, .>=, .\, .^, /, //, <, <:, <<, <=, ==, >, >=, >>, .>>, .<<, >>>, <|, |>, \, ^, |, ~, !==, ===, >:, colon, hcat, vcat, hvcat, getindex, setindex!, transpose, ctranspose, diff --git a/base/promotion.jl b/base/promotion.jl index 82c813064e3440..e61744e9ca3ec4 100644 --- a/base/promotion.jl +++ b/base/promotion.jl @@ -198,7 +198,7 @@ muladd(x::Number, y::Number, z::Number) = muladd(promote(x,y,z)...) (&)(x::Integer, y::Integer) = (&)(promote(x,y)...) (|)(x::Integer, y::Integer) = (|)(promote(x,y)...) -($)(x::Integer, y::Integer) = ($)(promote(x,y)...) +xor(x::Integer, y::Integer) = xor(promote(x,y)...) ==(x::Number, y::Number) = (==)(promote(x,y)...) <( x::Real, y::Real) = (< )(promote(x,y)...) @@ -253,7 +253,7 @@ muladd{T<:Number}(x::T, y::T, z::T) = x*y+z (&){T<:Integer}(x::T, y::T) = no_op_err("&", T) (|){T<:Integer}(x::T, y::T) = no_op_err("|", T) -($){T<:Integer}(x::T, y::T) = no_op_err("\$", T) +xor{T<:Integer}(x::T, y::T) = no_op_err("xor", T) =={T<:Number}(x::T, y::T) = x === y <{T<:Real}(x::T, y::T) = no_op_err("<" , T) diff --git a/base/random.jl b/base/random.jl index fffa9572426798..e8a91237450ade 100644 --- a/base/random.jl +++ b/base/random.jl @@ -324,14 +324,14 @@ rand(r::Union{RandomDevice,MersenneTwister}, ::Type{Float32}) = function rand(r::MersenneTwister, ::Type{UInt64}) reserve(r, 2) - rand_ui52_raw_inbounds(r) << 32 $ rand_ui52_raw_inbounds(r) + xor(rand_ui52_raw_inbounds(r) << 32, rand_ui52_raw_inbounds(r)) end function rand(r::MersenneTwister, ::Type{UInt128}) reserve(r, 3) - rand_ui52_raw_inbounds(r) % UInt128 << 96 $ - rand_ui52_raw_inbounds(r) % UInt128 << 48 $ - rand_ui52_raw_inbounds(r) + xor(rand_ui52_raw_inbounds(r) % UInt128 << 96, + rand_ui52_raw_inbounds(r) % UInt128 << 48, + rand_ui52_raw_inbounds(r)) end rand(r::MersenneTwister, ::Type{Int64}) = reinterpret(Int64, rand(r, UInt64)) @@ -447,7 +447,7 @@ function rand!{T<:Union{Float16, Float32}}(r::MersenneTwister, A::Array{T}, ::Ty A128 = unsafe_wrap(Array, convert(Ptr{UInt128}, pointer(A)), n128) @inbounds for i in 1:n128 u = A128[i] - u $= u << 26 + u = xor(u, u << 26) # at this point, the 64 low bits of u, "k" being the k-th bit of A128[i] and "+" the bit xor, are: # [..., 58+32,..., 53+27, 52+26, ..., 33+7, 32+6, ..., 27+1, 26, ..., 1] # the bits needing to be random are @@ -488,17 +488,17 @@ function rand!(r::MersenneTwister, A::Array{UInt128}, n::Int=length(A)) i = 0 @inbounds while n-i >= 5 u = A[i+=1] - A[n] $= u << 48 - A[n-=1] $= u << 36 - A[n-=1] $= u << 24 - A[n-=1] $= u << 12 - n-=1 + A[n] = xor(A[n], u << 48) + A[n-1] = xor(A[n-1], u << 36) + A[n-2] = xor(A[n-2], u << 24) + A[n-3] = xor(A[n-3], u << 12) + n -= 4 end end if n > 0 u = rand_ui2x52_raw(r) for i = 1:n - @inbounds A[i] $= u << 12*i + @inbounds A[i] = xor(A[i], u << 12*i) end end A diff --git a/base/set.jl b/base/set.jl index 28a8b05e992092..a47a76460a0a42 100644 --- a/base/set.jl +++ b/base/set.jl @@ -189,7 +189,7 @@ const hashs_seed = UInt === UInt64 ? 0x852ada37cfe8e0ce : 0xcfe8e0ce function hash(s::Set, h::UInt) h = hash(hashs_seed, h) for x in s - h $= hash(x) + h = xor(h, hash(x)) end return h end diff --git a/base/sparse/sparse.jl b/base/sparse/sparse.jl index 1936ca01f4e755..8cd969f4c90952 100644 --- a/base/sparse/sparse.jl +++ b/base/sparse/sparse.jl @@ -6,7 +6,7 @@ using Base: ReshapedArray, promote_op, setindex_shape_check, to_shape using Base.Sort: Forward using Base.LinAlg: AbstractTriangular, PosDefException -import Base: +, -, *, \, &, |, $, .+, .-, .*, ./, .\, .^, .<, .!=, == +import Base: +, -, *, \, &, |, xor, .+, .-, .*, ./, .\, .^, .<, .!=, == import Base: A_mul_B!, Ac_mul_B, Ac_mul_B!, At_mul_B, At_mul_B! import Base: A_mul_Bc, A_mul_Bt, Ac_mul_Bc, At_mul_Bt import Base: At_ldiv_B, Ac_ldiv_B, A_ldiv_B! diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index f1bfb662f567f3..b48ad0f7316312 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -904,7 +904,7 @@ function _ispermutationvalid_permute!{Ti<:Integer,Tp<:Integer}(perm::AbstractVec n = length(perm) checkspace[1:n] = 0 for k in perm - (0 < k <= n) && ((checkspace[k] $= 1) == 1) || return false + (0 < k ≤ n) && ((checkspace[k] = xor(checkspace[k], 1)) == 1) || return false end return true end @@ -1751,7 +1751,7 @@ broadcast_zpreserving{Tv,Ti}(f::Function, A_1::Union{Array,BitArray,Number}, A_2 ## Binary arithmetic and boolean operators -for op in (+, -, min, max, &, |, $) +for op in (+, -, min, max, &, |, xor) body = gen_broadcast_body_sparse(op, true) OP = Symbol(string(op)) @eval begin diff --git a/doc/manual/mathematical-operations.rst b/doc/manual/mathematical-operations.rst index c7afc243c7590e..d19560db94e7f4 100644 --- a/doc/manual/mathematical-operations.rst +++ b/doc/manual/mathematical-operations.rst @@ -68,17 +68,17 @@ The following `bitwise operators `_ are supported on all primitive integer types: -=========== ========================================================================= -Expression Name -=========== ========================================================================= -``~x`` bitwise not -``x & y`` bitwise and -``x | y`` bitwise or -``x $ y`` bitwise xor (exclusive or) -``x >>> y`` `logical shift `_ right -``x >> y`` `arithmetic shift `_ right -``x << y`` logical/arithmetic shift left -=========== ========================================================================= +=========== ========================================================================= +Expression Name +=========== ========================================================================= +``~x`` bitwise not +``x & y`` bitwise and +``x | y`` bitwise or +``xor(x, y)`` bitwise xor (exclusive or) +``x >>> y`` `logical shift `_ right +``x >> y`` `arithmetic shift `_ right +``x << y`` logical/arithmetic shift left +=========== ========================================================================= Here are some examples with bitwise operators: @@ -93,7 +93,7 @@ Here are some examples with bitwise operators: julia> 123 | 234 251 - julia> 123 $ 234 + julia> xor(123, 234) 145 julia> ~UInt32(123) @@ -122,7 +122,7 @@ equivalent to writing ``x = x + 3``:: The updating versions of all the binary arithmetic and bitwise operators are:: - += -= *= /= \= ÷= %= ^= &= |= $= >>>= >>= <<= + += -= *= /= \= ÷= %= ^= &= |= >>>= >>= <<= .. note:: @@ -344,11 +344,11 @@ Exponentiation ``^`` and its elementwise equivalent ``.^`` Fractions ``//`` and ``.//`` Multiplication ``* / % & \`` and ``.* ./ .% .\`` Bitshifts ``<< >> >>>`` and ``.<< .>> .>>>`` -Addition ``+ - | $`` and ``.+ .-`` +Addition ``+ - |`` and ``.+ .-`` Syntax ``: ..`` followed by ``|>`` Comparisons ``> < >= <= == === != !== <:`` and ``.> .< .>= .<= .== .!=`` Control flow ``&&`` followed by ``||`` followed by ``?`` -Assignments ``= += -= *= /= //= \= ^= ÷= %= |= &= $= <<= >>= >>>=`` and ``.+= .-= .*= ./= .//= .\= .^= .÷= .%=`` +Assignments ``= += -= *= /= //= \= ^= ÷= %= |= &= <<= >>= >>>=`` and ``.+= .-= .*= ./= .//= .\= .^= .÷= .%=`` ================= ============================================================================================= .. _man-elementary-functions: diff --git a/test/bigint.jl b/test/bigint.jl index 9a653a6569f822..de5a1a07949fc9 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -164,7 +164,7 @@ end @test ~BigInt(123) == -124 @test BigInt(123) & BigInt(234) == 106 @test BigInt(123) | BigInt(234) == 251 -@test BigInt(123) $ BigInt(234) == 145 +@test xor(BigInt(123), BigInt(234)) == 145 @test gcd(BigInt(48), BigInt(180)) == 12 @test lcm(BigInt(48), BigInt(180)) == 720 @@ -199,11 +199,11 @@ g = parse(BigInt,"-1") @test *(a, b, c, d, f) == parse(BigInt,"-45258849200337190631492857400003938881995610529251881450243326128168934937055005474972396281351684800") @test *(a, b, c, d, f, g) == parse(BigInt,"45258849200337190631492857400003938881995610529251881450243326128168934937055005474972396281351684800") -@test ($)(a, b) == parse(BigInt,"327299") -@test ($)(a, b, c) == parse(BigInt,"3426495623485904783798472") -@test ($)(a, b, c, d) == parse(BigInt,"-3426495623485906178489610") -@test ($)(a, b, c, d, f) == parse(BigInt,"-2413804710837418037418307081437316711364709261074607933698") -@test ($)(a, b, c, d, f, g) == parse(BigInt,"2413804710837418037418307081437316711364709261074607933697") +@test xor(a, b) == parse(BigInt,"327299") +@test xor(a, b, c) == parse(BigInt,"3426495623485904783798472") +@test xor(a, b, c, d) == parse(BigInt,"-3426495623485906178489610") +@test xor(a, b, c, d, f) == parse(BigInt,"-2413804710837418037418307081437316711364709261074607933698") +@test xor(a, b, c, d, f, g) == parse(BigInt,"2413804710837418037418307081437316711364709261074607933697") @test (&)(a, b) == parse(BigInt,"124") @test (&)(a, b, c) == parse(BigInt,"72") diff --git a/test/bitarray.jl b/test/bitarray.jl index 06ae7f9b9a4b44..956cf4e5e6920a 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -784,7 +784,7 @@ let b1 = bitrand(n1, n2) b2 = bitrand(n1, n2) @check_bit_operation (&)(b1, b2) BitMatrix @check_bit_operation (|)(b1, b2) BitMatrix - @check_bit_operation ($)(b1, b2) BitMatrix + @check_bit_operation xor(b1, b2) BitMatrix @check_bit_operation (+)(b1, b2) Matrix{Int} @check_bit_operation (-)(b1, b2) Matrix{Int} @check_bit_operation (.*)(b1, b2) BitMatrix @@ -815,7 +815,7 @@ end let b0 = falses(0) @check_bit_operation (&)(b0, b0) BitVector @check_bit_operation (|)(b0, b0) BitVector - @check_bit_operation ($)(b0, b0) BitVector + @check_bit_operation xor(b0, b0) BitVector @check_bit_operation (.*)(b0, b0) BitVector @check_bit_operation (*)(b0, b0') Matrix{Int} end @@ -826,7 +826,7 @@ let b1 = bitrand(n1, n2) i2 = rand(1:10, n1, n2) @check_bit_operation (&)(b1, i2) Matrix{Int} @check_bit_operation (|)(b1, i2) Matrix{Int} - @check_bit_operation ($)(b1, i2) Matrix{Int} + @check_bit_operation xor(b1, i2) Matrix{Int} @check_bit_operation (+)(b1, i2) Matrix{Int} @check_bit_operation (-)(b1, i2) Matrix{Int} @check_bit_operation (.*)(b1, i2) Matrix{Int} @@ -859,14 +859,14 @@ let b2 = bitrand(n1, n2) @check_bit_operation (&)(i1, b2) Matrix{Int} @check_bit_operation (|)(i1, b2) Matrix{Int} - @check_bit_operation ($)(i1, b2) Matrix{Int} + @check_bit_operation xor(i1, b2) Matrix{Int} @check_bit_operation (.+)(i1, b2) Matrix{Int} @check_bit_operation (.-)(i1, b2) Matrix{Int} @check_bit_operation (.*)(i1, b2) Matrix{Int} @check_bit_operation (&)(u1, b2) Matrix{UInt8} @check_bit_operation (|)(u1, b2) Matrix{UInt8} - @check_bit_operation ($)(u1, b2) Matrix{UInt8} + @check_bit_operation xor(u1, b2) Matrix{UInt8} @check_bit_operation (.+)(u1, b2) Matrix{UInt8} @check_bit_operation (.-)(u1, b2) Matrix{UInt8} @check_bit_operation (.*)(u1, b2) Matrix{UInt8} @@ -941,10 +941,10 @@ let b1 = bitrand(n1, n2) @check_bit_operation (|)(b1, false) BitMatrix @check_bit_operation (|)(true, b1) BitMatrix @check_bit_operation (|)(false, b1) BitMatrix - @check_bit_operation ($)(b1, true) BitMatrix - @check_bit_operation ($)(b1, false) BitMatrix - @check_bit_operation ($)(true, b1) BitMatrix - @check_bit_operation ($)(false, b1) BitMatrix + @check_bit_operation xor(b1, true) BitMatrix + @check_bit_operation xor(b1, false) BitMatrix + @check_bit_operation xor(true, b1) BitMatrix + @check_bit_operation xor(false, b1) BitMatrix @check_bit_operation (.+)(b1, true) Matrix{Int} @check_bit_operation (.+)(b1, false) Matrix{Int} @check_bit_operation (.-)(b1, true) Matrix{Int} @@ -960,13 +960,13 @@ let b1 = bitrand(n1, n2) @check_bit_operation (&)(b1, b2) BitMatrix @check_bit_operation (|)(b1, b2) BitMatrix - @check_bit_operation ($)(b1, b2) BitMatrix + @check_bit_operation xor(b1, b2) BitMatrix @check_bit_operation (&)(b2, b1) BitMatrix @check_bit_operation (|)(b2, b1) BitMatrix - @check_bit_operation ($)(b2, b1) BitMatrix + @check_bit_operation xor(b2, b1) BitMatrix @check_bit_operation (&)(b1, i2) Matrix{Int} @check_bit_operation (|)(b1, i2) Matrix{Int} - @check_bit_operation ($)(b1, i2) Matrix{Int} + @check_bit_operation xor(b1, i2) Matrix{Int} @check_bit_operation (.+)(b1, i2) Matrix{Int} @check_bit_operation (.-)(b1, i2) Matrix{Int} @check_bit_operation (.*)(b1, i2) Matrix{Int} @@ -976,7 +976,7 @@ let b1 = bitrand(n1, n2) @check_bit_operation (&)(b1, u2) Matrix{UInt8} @check_bit_operation (|)(b1, u2) Matrix{UInt8} - @check_bit_operation ($)(b1, u2) Matrix{UInt8} + @check_bit_operation xor(b1, u2) Matrix{UInt8} @check_bit_operation (.+)(b1, u2) Matrix{UInt8} @check_bit_operation (.-)(b1, u2) Matrix{UInt8} @check_bit_operation (.*)(b1, u2) Matrix{UInt8} @@ -1119,7 +1119,7 @@ let b1 = trues(v1) for i = 3:(v1-1), j = 2:i submask = b1 << (v1-j+1) @test findnext((b1 >> i) | submask, j) == i+1 - @test findnextnot((~(b1 >> i)) $ submask, j) == i+1 + @test findnextnot(xor(~(b1 >> i), submask), j) == i+1 end end @@ -1276,7 +1276,7 @@ for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] @test map(&, b1, b2) == map((x,y)->x&y, b1, b2) == b1 & b2 @test map(|, b1, b2) == map((x,y)->x|y, b1, b2) == b1 | b2 - @test map($, b1, b2) == map((x,y)->x$y, b1, b2) == b1 $ b2 + @test map(xor, b1, b2) == map((x,y)->xor(x,y), b1, b2) == xor(b1, b2) @test map(^, b1, b2) == map((x,y)->x^y, b1, b2) == b1 .^ b2 @test map(*, b1, b2) == map((x,y)->x*y, b1, b2) == b1 .* b2 @@ -1301,7 +1301,7 @@ for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] @test map!(&, b, b1, b2) == map!((x,y)->x&y, b, b1, b2) == b1 & b2 == b @test map!(|, b, b1, b2) == map!((x,y)->x|y, b, b1, b2) == b1 | b2 == b - @test map!($, b, b1, b2) == map!((x,y)->x$y, b, b1, b2) == b1 $ b2 == b + @test map!(xor, b, b1, b2) == map!((x,y)->xor(x,y), b, b1, b2) == xor(b1, b2) == b @test map!(^, b, b1, b2) == map!((x,y)->x^y, b, b1, b2) == b1 .^ b2 == b @test map!(*, b, b1, b2) == map!((x,y)->x*y, b, b1, b2) == b1 .* b2 == b diff --git a/test/numbers.jl b/test/numbers.jl index c90a61d44fcc2d..945a4122d6d069 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -26,10 +26,10 @@ const ≣ = isequal # convenient for comparing NaNs @test false | true == true @test true | true == true -@test false $ false == false -@test true $ false == true -@test false $ true == true -@test true $ true == false +@test xor(false, false) == false +@test xor(true, false) == true +@test xor(false, true) == true +@test xor(true, true) == false # the bool operator @test Bool(false) == false diff --git a/test/operators.jl b/test/operators.jl index 864f0a764e49c8..35ff0a6ccaf967 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -43,7 +43,7 @@ p = 1=>:foo @test p[endof(p)] == p[end] == p[2] == :foo @test (|)(2) == 2 -@test ($)(2) == 2 +@test xor(2) == 2 # @test ctranspose('a') == 'a' # (c)transpose of Chars no longer supported diff --git a/test/reduce.jl b/test/reduce.jl index 5d2a691a778299..6f07967553edcc 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -10,11 +10,11 @@ @test Base.mapfoldl(abs2, /, 2:5) ≈ 1/900 @test Base.mapfoldl(abs2, /, 10, 2:5) ≈ 1/1440 -@test Base.mapfoldl((x)-> x $ true, &, true, [true false true false false]) == false -@test Base.mapfoldl((x)-> x $ true, &, [true false true false false]) == false +@test Base.mapfoldl((x)-> xor(x, true), &, true, [true false true false false]) == false +@test Base.mapfoldl((x)-> xor(x, true), &, [true false true false false]) == false -@test Base.mapfoldl((x)-> x $ true, |, [true false true false false]) == true -@test Base.mapfoldl((x)-> x $ true, |, false, [true false true false false]) == true +@test Base.mapfoldl((x)-> xor(x, true), |, [true false true false false]) == true +@test Base.mapfoldl((x)-> xor(x, true), |, false, [true false true false false]) == true @test foldr(-, 1:5) == 3 @test foldr(-, 10, 1:5) == -7 diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index b56ad98a84d97d..0b8265ee6642a7 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -1494,8 +1494,8 @@ let @test A13024 | B13024 == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) @test typeof(A13024 | B13024) == SparseMatrixCSC{Bool,Int} - @test A13024 $ B13024 == sparse([3,4,4], [3,3,4], fill(true,3), 5, 5) - @test typeof(A13024 $ B13024) == SparseMatrixCSC{Bool,Int} + @test xor(A13024, B13024) == sparse([3,4,4], [3,3,4], fill(true,3), 5, 5) + @test typeof(xor(A13024, B13024)) == SparseMatrixCSC{Bool,Int} @test max(A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) @test typeof(max(A13024, B13024)) == SparseMatrixCSC{Bool,Int} @@ -1503,7 +1503,7 @@ let @test min(A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3)) @test typeof(min(A13024, B13024)) == SparseMatrixCSC{Bool,Int} - for op in (+, -, &, |, $) + for op in (+, -, &, |, xor) @test op(A13024, B13024) == op(Array(A13024), Array(B13024)) end for op in (max, min)