Skip to content

Commit 91e01b1

Browse files
committed
Add ⊻ as alternative to xor, and ⊻= as alternative to $=.
Please note that `⊻=` is in the add-dots group in the parser, preparing for `.⊻=`. However, this commit does not implement `.⊻` yet, this should happen in a separate commit with `.&` and `.|` together.
1 parent af4003e commit 91e01b1

32 files changed

+99
-79
lines changed

base/associative.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const hasha_seed = UInt === UInt64 ? 0x6d35bb51952d5539 : 0x952d5539
251251
function hash(a::Associative, h::UInt)
252252
h = hash(hasha_seed, h)
253253
for (k,v) in a
254-
h = xor(h, hash(k, hash(v)))
254+
h ⊻= hash(k, hash(v))
255255
end
256256
return h
257257
end

base/broadcast.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ function broadcast_bitarrays(scalarf, bitf, A::AbstractArray{Bool}, B::AbstractA
498498
return F
499499
end
500500

501-
biteq(a::UInt64, b::UInt64) = xor(~a, b)
501+
biteq(a::UInt64, b::UInt64) = ~a b
502502
bitlt(a::UInt64, b::UInt64) = ~a & b
503-
bitneq(a::UInt64, b::UInt64) = xor(a, b)
503+
bitneq(a::UInt64, b::UInt64) = a b
504504
bitle(a::UInt64, b::UInt64) = ~a | b
505505

506506
.==(A::AbstractArray{Bool}, B::AbstractArray{Bool}) = broadcast_bitarrays(==, biteq, A, B)

base/char.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ in(x::Char, y::Char) = x == y
3333
isless(x::Char, y::Char) = UInt32(x) < UInt32(y)
3434

3535
const hashchar_seed = 0xd4d64234
36-
hash(x::Char, h::UInt) = hash_uint64(xor((UInt64(x)+hashchar_seed)<<32, UInt64(h)))
36+
hash(x::Char, h::UInt) = hash_uint64(((UInt64(x)+hashchar_seed)<<32) UInt64(h))
3737

3838
-(x::Char, y::Char) = Int(x) - Int(y)
3939
-(x::Char, y::Integer) = Char(Int32(x) - Int32(y))

base/combinatorics.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function isperm(A)
7373
n = length(A)
7474
used = falses(n)
7575
for a in A
76-
(0 < a <= n) && (used[a] = xor(used[a], true)) || return false
76+
(0 < a <= n) && (used[a] ⊻= true) || return false
7777
end
7878
true
7979
end

base/complex.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ const hash_0_imag = hash(0, h_imag)
161161

162162
function hash(z::Complex, h::UInt)
163163
# TODO: with default argument specialization, this would be better:
164-
# hash(real(z), h $ hash(imag(z), h $ h_imag) $ hash(0, h $ h_imag))
165-
hash(real(z), xor(h, hash(imag(z), h_imag), hash_0_imag))
164+
# hash(real(z), h hash(imag(z), h h_imag) hash(0, h h_imag))
165+
hash(real(z), h hash(imag(z), h_imag) hash_0_imag)
166166
end
167167

168168
## generic functions of complex numbers ##

base/dSFMT.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ function dsfmt_jump_add!(dest::Vector{UInt64}, src::Vector{UInt64})
115115
while i <= N-diff
116116
j = i*2-1
117117
p = j + diff*2
118-
dest[j] = xor(dest[j], src[p])
119-
dest[j+1] = xor(dest[j+1], src[p+1])
118+
dest[j] ⊻= src[p]
119+
dest[j+1] ⊻= src[p+1]
120120
i += 1
121121
end
122122
while i <= N
123123
j = i*2-1
124124
p = j + (diff - N)*2
125-
dest[j] = xor(dest[j], src[p])
126-
dest[j+1] = xor(dest[j+1], src[p+1])
125+
dest[j] ⊻= src[p]
126+
dest[j+1] ⊻= src[p+1]
127127
i += 1
128128
end
129-
dest[N*2+1] = xor(dest[N*2+1], src[N*2+1])
130-
dest[N*2+2] = xor(dest[N*2+2], src[N*2+2])
129+
dest[N*2+1] ⊻= src[N*2+1]
130+
dest[N*2+2] ⊻= src[N*2+2]
131131
return dest
132132
end
133133

base/deprecated.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,11 @@ end))
10231023
@deprecate ipermutedims(A::AbstractArray,p) permutedims(A, invperm(p))
10241024

10251025
# 18696
1026-
@deprecate ($) xor
1026+
function ($)(x, y)
1027+
depwarn("`x \$ y` is deprecated. use `xor(x, y)` or `x ⊻ y` instead.", :$)
1028+
xor(x, y)
1029+
end
1030+
export $
10271031

10281032
@deprecate is (===)
10291033

base/docs/helpdb/Base.jl

+1
Original file line numberDiff line numberDiff line change
@@ -3355,6 +3355,7 @@ dawson
33553355

33563356
"""
33573357
xor(x, y)
3358+
⊻(x, y)
33583359
33593360
Bitwise exclusive or.
33603361
"""

base/exports.jl

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export
206206
,
207207
,
208208
xor,
209+
,
209210
%,
210211
÷,
211212
&,

base/fastmath.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ mul_fast{T<:FloatTypes}(x::T, y::T, zs::T...) =
153153
cmp_fast{T<:FloatTypes}(x::T, y::T) = ifelse(x==y, 0, ifelse(x<y, -1, +1))
154154
function mod_fast{T<:FloatTypes}(x::T, y::T)
155155
r = rem(x,y)
156-
ifelse(xor(r > 0, y > 0), r+y, r)
156+
ifelse((r > 0) (y > 0), r+y, r)
157157
end
158158
end
159159

base/float.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ _default_type(T::Union{Type{Real},Type{AbstractFloat}}) = Float64
361361
## floating point arithmetic ##
362362
-(x::Float64) = box(Float64,neg_float(unbox(Float64,x)))
363363
-(x::Float32) = box(Float32,neg_float(unbox(Float32,x)))
364-
-(x::Float16) = reinterpret(Float16, xor(reinterpret(UInt16,x), 0x8000))
364+
-(x::Float16) = reinterpret(Float16, reinterpret(UInt16,x) 0x8000)
365365

366366
for op in (:+,:-,:*,:/,:\,:^)
367367
@eval ($op)(a::Float16, b::Float16) = Float16(($op)(Float32(a), Float32(b)))
@@ -400,7 +400,7 @@ function mod{T<:AbstractFloat}(x::T, y::T)
400400
r = rem(x,y)
401401
if r == 0
402402
copysign(r,y)
403-
elseif xor(r > 0, y > 0)
403+
elseif (r > 0) (y > 0)
404404
r+y
405405
else
406406
r
@@ -531,7 +531,7 @@ const hx_NaN = hx(UInt64(0), NaN, UInt(0 ))
531531

532532
hash(x::UInt64, h::UInt) = hx(x, Float64(x), h)
533533
hash(x::Int64, h::UInt) = hx(reinterpret(UInt64,abs(x)), Float64(x), h)
534-
hash(x::Float64, h::UInt) = isnan(x) ? xor(hx_NaN, h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h)
534+
hash(x::Float64, h::UInt) = isnan(x) ? (hx_NaN h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h)
535535

536536
hash(x::Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h)
537537
hash(x::Float32, h::UInt) = hash(Float64(x), h)
@@ -577,7 +577,7 @@ function nextfloat(f::Union{Float16,Float32,Float64}, d::Integer)
577577
fu = fumax
578578
else
579579
du = da % U
580-
if xor(fneg, dneg)
580+
if fneg dneg
581581
if du > fu
582582
fu = min(fumax, du - fu)
583583
fneg = !fneg

base/gmp.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function convert{T<:Signed}(::Type{T}, x::BigInt)
194194
else
195195
0 <= n <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError())
196196
y = x % T
197-
xor(x.size > 0, y > 0) && throw(InexactError()) # catch overflow
197+
(x.size > 0) (y > 0) && throw(InexactError()) # catch overflow
198198
y
199199
end
200200
end

base/hashing.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,34 @@ hash(x::ANY, h::UInt) = 3*object_id(x) - h
1414
function hash_64_64(n::UInt64)
1515
local a::UInt64 = n
1616
a = ~a + a << 21
17-
a = xor(a, a >> 24)
17+
a = a a >> 24
1818
a = a + a << 3 + a << 8
19-
a = xor(a, a >> 14)
19+
a = a a >> 14
2020
a = a + a << 2 + a << 4
21-
a = xor(a, a >> 28)
21+
a = a a >> 28
2222
a = a + a << 31
2323
return a
2424
end
2525

2626
function hash_64_32(n::UInt64)
2727
local a::UInt64 = n
2828
a = ~a + a << 18
29-
a = xor(a, a >> 31)
29+
a = a a >> 31
3030
a = a * 21
31-
a = xor(a, a >> 11)
31+
a = a a >> 11
3232
a = a + a << 6
33-
a = xor(a, a >> 22)
33+
a = a a >> 22
3434
return a % UInt32
3535
end
3636

3737
function hash_32_32(n::UInt32)
3838
local a::UInt32 = n
3939
a = a + 0x7ed55d16 + a << 12
40-
a = xor(a, 0xc761c23c, a >> 19)
40+
a = a 0xc761c23c a >> 19
4141
a = a + 0x165667b1 + a << 5
42-
a = a + xor(0xd3a2646c, a << 9)
42+
a = a + 0xd3a2646c a << 9
4343
a = a + 0xfd7046c5 + a << 3
44-
a = xor(a, 0xb55a4f09, a >> 16)
44+
a = a 0xb55a4f09 a >> 16
4545
return a
4646
end
4747

base/hashing2.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
## efficient value-based hashing of integers ##
44

55
function hash_integer(n::Integer, h::UInt)
6-
h = xor(hash_uint(xor(n % UInt, h)), h)
6+
h ⊻= hash_uint((n % UInt) h)
77
n = abs(n)
88
n >>>= sizeof(UInt) << 3
99
while n != 0
10-
h = xor(hash_uint(xor(n % UInt, h)), h)
10+
h ⊻= hash_uint((n % UInt) h)
1111
n >>>= sizeof(UInt) << 3
1212
end
1313
return h
@@ -18,9 +18,9 @@ function hash_integer(n::BigInt, h::UInt)
1818
s == 0 && return hash_integer(0, h)
1919
p = convert(Ptr{UInt}, n.d)
2020
b = unsafe_load(p)
21-
h = xor(hash_uint(xor(ifelse(s < 0, -b, b), h)), h)
21+
h ⊻= hash_uint(ifelse(s < 0, -b, b) h)
2222
for k = 2:abs(s)
23-
h = xor(hash_uint(xor(unsafe_load(p, k), h)), h)
23+
h ⊻= hash_uint(unsafe_load(p, k) h)
2424
end
2525
return h
2626
end

base/int.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ flipsign(x::Signed, y::Float32) = flipsign(x, reinterpret(Int32,y))
7676
flipsign(x::Signed, y::Float64) = flipsign(x, reinterpret(Int64,y))
7777
flipsign(x::Signed, y::Real) = flipsign(x, -oftype(x,signbit(y)))
7878

79-
copysign(x::Signed, y::Signed) = flipsign(x, xor(x,y))
79+
copysign(x::Signed, y::Signed) = flipsign(x, x y)
8080
copysign(x::Signed, y::Float16) = copysign(x, reinterpret(Int16,y))
8181
copysign(x::Signed, y::Float32) = copysign(x, reinterpret(Int32,y))
8282
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)
149149
fld{T<:Unsigned}(x::T, y::T) = div(x,y)
150150
function fld{T<:Integer}(x::T, y::T)
151151
d = div(x,y)
152-
d - (signbit(xor(x,y)) & (d*y!=x))
152+
d - (signbit(x y) & (d*y!=x))
153153
end
154154

155155
# cld(x,y) = div(x,y) + ((x>0) == (y>0) && rem(x,y) != 0 ? 1 : 0)

base/intset.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function symdiff!(s::IntSet, n::Integer)
140140
elseif n < 0
141141
throw(ArgumentError("IntSet elements cannot be negative"))
142142
end
143-
s.bits[n>>5 + 1] = xor(s.bits[n>>5 + 1], UInt32(1)<<(n&31))
143+
s.bits[n>>5 + 1] ⊻= UInt32(1)<<(n&31)
144144
return s
145145
end
146146

@@ -282,14 +282,14 @@ function symdiff!(s::IntSet, s2::IntSet)
282282
end
283283
lim = length(s2.bits)
284284
for n = 1:lim
285-
s.bits[n] = xor(s.bits[n], s2.bits[n])
285+
s.bits[n] ⊻= s2.bits[n]
286286
end
287287
if s2.fill1s
288288
for n=lim+1:length(s.bits)
289289
s.bits[n] = ~s.bits[n]
290290
end
291291
end
292-
s.fill1s = xor(s.fill1s, s2.fill1s)
292+
s.fill1s ⊻= s2.fill1s
293293
s
294294
end
295295

base/latex_symbols.jl

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const latex_symbols = Dict(
8383
"\\pppprime" => "",
8484
"\\backpprime" => "",
8585
"\\backppprime" => "",
86+
"\\xor" => "",
8687

8788
# Superscripts
8889
"\\^0" => "",

base/math.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ function significand{T<:AbstractFloat}(x::T)
393393
if xe == 0 # x is subnormal
394394
x == 0 && return x
395395
xs = xu & sign_mask(T)
396-
xu = xor(xu, xs)
396+
xu ⊻= xs
397397
m = leading_zeros(xu)-exponent_bits(T)
398398
xu <<= m
399-
xu = xor(xu, xs)
399+
xu ⊻= xs
400400
elseif xe == exponent_mask(T) # NaN or Inf
401401
return x
402402
end
@@ -419,7 +419,7 @@ function frexp{T<:AbstractFloat}(x::T)
419419
xs == 0 && return x, 0 # +-0
420420
m = unsigned(leading_zeros(xs) - exponent_bits(T))
421421
xs <<= m
422-
xu = xor(xs, (xu & sign_mask(T)))
422+
xu = xs (xu & sign_mask(T))
423423
k = 1 - signed(m)
424424
end
425425
k -= (exponent_bias(T) - 1)

base/operators.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ identity(x) = x
267267
(|)(x::Integer) = x
268268
xor(x::Integer) = x
269269

270+
const = xor
271+
270272
# foldl for argument lists. expand recursively up to a point, then
271273
# switch to a loop. this allows small cases like `a+b+c+d` to be inlined
272274
# efficiently, without a major slowdown for `+(x...)` when `x` is big.
@@ -1042,6 +1044,7 @@ export
10421044
,
10431045
,
10441046
,
1047+
,
10451048
colon,
10461049
hcat,
10471050
vcat,
@@ -1055,6 +1058,6 @@ import ..this_module: !, !=, xor, %, .%, ÷, .÷, &, *, +, -, .!=, .+, .-, .*, .
10551058
.>=, .\, .^, /, //, <, <:, <<, <=, ==, >, >=, >>, .>>, .<<, >>>,
10561059
<|, |>, \, ^, |, ~, !==, ===, >:, colon, hcat, vcat, hvcat, getindex, setindex!,
10571060
transpose, ctranspose,
1058-
, , , .≥, .≤, .≠, , ×, , , , , , , , , , ,
1061+
, , , .≥, .≤, .≠, , ×, , , , , , , , , , , ,
10591062

10601063
end

base/random.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ rand(r::Union{RandomDevice,MersenneTwister}, ::Type{Float32}) =
324324

325325
function rand(r::MersenneTwister, ::Type{UInt64})
326326
reserve(r, 2)
327-
xor(rand_ui52_raw_inbounds(r) << 32, rand_ui52_raw_inbounds(r))
327+
rand_ui52_raw_inbounds(r) << 32 rand_ui52_raw_inbounds(r)
328328
end
329329

330330
function rand(r::MersenneTwister, ::Type{UInt128})
@@ -447,7 +447,7 @@ function rand!{T<:Union{Float16, Float32}}(r::MersenneTwister, A::Array{T}, ::Ty
447447
A128 = unsafe_wrap(Array, convert(Ptr{UInt128}, pointer(A)), n128)
448448
@inbounds for i in 1:n128
449449
u = A128[i]
450-
u = xor(u, u << 26)
450+
u ⊻= u << 26
451451
# at this point, the 64 low bits of u, "k" being the k-th bit of A128[i] and "+" the bit xor, are:
452452
# [..., 58+32,..., 53+27, 52+26, ..., 33+7, 32+6, ..., 27+1, 26, ..., 1]
453453
# the bits needing to be random are
@@ -488,17 +488,17 @@ function rand!(r::MersenneTwister, A::Array{UInt128}, n::Int=length(A))
488488
i = 0
489489
@inbounds while n-i >= 5
490490
u = A[i+=1]
491-
A[n] = xor(A[n], u << 48)
492-
A[n-1] = xor(A[n-1], u << 36)
493-
A[n-2] = xor(A[n-2], u << 24)
494-
A[n-3] = xor(A[n-3], u << 12)
495-
n -= 4
491+
A[n] ⊻= u << 48
492+
A[n-=1] ⊻= u << 36
493+
A[n-=1] ⊻= u << 24
494+
A[n-=1] ⊻= u << 12
495+
n-=1
496496
end
497497
end
498498
if n > 0
499499
u = rand_ui2x52_raw(r)
500500
for i = 1:n
501-
@inbounds A[i] = xor(A[i], u << 12*i)
501+
@inbounds A[i] ⊻= u << 12*i
502502
end
503503
end
504504
A

base/set.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const hashs_seed = UInt === UInt64 ? 0x852ada37cfe8e0ce : 0xcfe8e0ce
189189
function hash(s::Set, h::UInt)
190190
h = hash(hashs_seed, h)
191191
for x in s
192-
h = xor(h, hash(x))
192+
h ⊻= hash(x)
193193
end
194194
return h
195195
end

base/show.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ const uni_ops = Set{Symbol}([:(+), :(-), :(!), :(¬), :(~), :(<:), :(>:), :(√)
449449
const expr_infix_wide = Set{Symbol}([
450450
:(=), :(+=), :(-=), :(*=), :(/=), :(\=), :(^=), :(&=), :(|=), :(÷=), :(%=), :(>>>=), :(>>=), :(<<=),
451451
:(.=), :(.+=), :(.-=), :(.*=), :(./=), :(.\=), :(.^=), :(.&=), :(.|=), :(.÷=), :(.%=), :(.>>>=), :(.>>=), :(.<<=),
452-
:(&&), :(||), :(<:), :(=>), :($=)])
452+
:(&&), :(||), :(<:), :(=>), :($=), :(⊻=)])
453453
const expr_infix = Set{Symbol}([:(:), :(->), Symbol("::")])
454454
const expr_infix_any = union(expr_infix, expr_infix_wide)
455455
const all_ops = union(quoted_syms, uni_ops, expr_infix_any)

base/sparse/sparsematrix.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ function _ispermutationvalid_permute!{Ti<:Integer,Tp<:Integer}(perm::AbstractVec
904904
n = length(perm)
905905
checkspace[1:n] = 0
906906
for k in perm
907-
(0 < k n) && ((checkspace[k] = xor(checkspace[k], 1)) == 1) || return false
907+
(0 < k n) && ((checkspace[k] ⊻= 1) == 1) || return false
908908
end
909909
return true
910910
end

0 commit comments

Comments
 (0)