Skip to content

Commit e296b3e

Browse files
committed
Add ⊻ as alternative to xor, and ⊻= as alternative to $=.
1 parent 63bbaef commit e296b3e

33 files changed

+100
-81
lines changed

base/associative.jl

Lines changed: 1 addition & 1 deletion
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/bitarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ map!(f::typeof(max), dest::BitArray, A::BitArray, B::BitArray) = map!(|, dest, A
20102010
map!(f::typeof(!=), dest::BitArray, A::BitArray, B::BitArray) = map!(xor, dest, A, B)
20112011
map!(f::Union{typeof(>=), typeof(^)}, dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> p | ~q), dest, A, B)
20122012
map!(f::typeof(<=), dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> ~p | q), dest, A, B)
2013-
map!(f::typeof(==), dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> ~xor(p, q)), dest, A, B)
2013+
map!(f::typeof(==), dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> ~(p q)), dest, A, B)
20142014
map!(f::typeof(<), dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> ~p & q), dest, A, B)
20152015
map!(f::typeof(>), dest::BitArray, A::BitArray, B::BitArray) = map!(BitChunkFunctor((p, q) -> p & ~q), dest, A, B)
20162016

base/broadcast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ function broadcast_bitarrays(scalarf, bitf, A::AbstractArray{Bool}, B::AbstractA
472472
return F
473473
end
474474

475-
biteq(a::UInt64, b::UInt64) = xor(~a, b)
475+
biteq(a::UInt64, b::UInt64) = ~a b
476476
bitlt(a::UInt64, b::UInt64) = ~a & b
477-
bitneq(a::UInt64, b::UInt64) = xor(a, b)
477+
bitneq(a::UInt64, b::UInt64) = a b
478478
bitle(a::UInt64, b::UInt64) = ~a | b
479479

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

base/char.jl

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ const hash_0_imag = hash(0, h_imag)
126126

127127
function hash(z::Complex, h::UInt)
128128
# TODO: with default argument specialization, this would be better:
129-
# hash(real(z), h $ hash(imag(z), h $ h_imag) $ hash(0, h $ h_imag))
130-
hash(real(z), xor(h, hash(imag(z), h_imag), hash_0_imag))
129+
# hash(real(z), h hash(imag(z), h h_imag) hash(0, h h_imag))
130+
hash(real(z), h hash(imag(z), h_imag) hash_0_imag)
131131
end
132132

133133
## generic functions of complex numbers ##

base/dSFMT.jl

Lines changed: 6 additions & 6 deletions
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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,11 @@ end))
10221022
@deprecate ipermutedims(A::AbstractArray,p) permutedims(A, invperm(p))
10231023

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

10271031
@deprecate is (===)
10281032

base/docs/helpdb/Base.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,6 +3395,7 @@ dawson
33953395

33963396
"""
33973397
xor(x, y)
3398+
⊻(x, y)
33983399
33993400
Bitwise exclusive or.
34003401
"""

base/exports.jl

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

base/fastmath.jl

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ _default_type(T::Union{Type{Real},Type{AbstractFloat}}) = Float64
342342
## floating point arithmetic ##
343343
-(x::Float64) = box(Float64,neg_float(unbox(Float64,x)))
344344
-(x::Float32) = box(Float32,neg_float(unbox(Float32,x)))
345-
-(x::Float16) = reinterpret(Float16, xor(reinterpret(UInt16,x), 0x8000))
345+
-(x::Float16) = reinterpret(Float16, reinterpret(UInt16,x) 0x8000)
346346

347347
for op in (:+,:-,:*,:/,:\,:^)
348348
@eval ($op)(a::Float16, b::Float16) = Float16(($op)(Float32(a), Float32(b)))
@@ -381,7 +381,7 @@ function mod{T<:AbstractFloat}(x::T, y::T)
381381
r = rem(x,y)
382382
if r == 0
383383
copysign(r,y)
384-
elseif xor(r > 0, y > 0)
384+
elseif (r > 0) (y > 0)
385385
r+y
386386
else
387387
r
@@ -512,7 +512,7 @@ const hx_NaN = hx(UInt64(0), NaN, UInt(0 ))
512512

513513
hash(x::UInt64, h::UInt) = hx(x, Float64(x), h)
514514
hash(x::Int64, h::UInt) = hx(reinterpret(UInt64,abs(x)), Float64(x), h)
515-
hash(x::Float64, h::UInt) = isnan(x) ? xor(hx_NaN, h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h)
515+
hash(x::Float64, h::UInt) = isnan(x) ? (hx_NaN h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h)
516516

517517
hash(x::Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h)
518518
hash(x::Float32, h::UInt) = hash(Float64(x), h)
@@ -558,7 +558,7 @@ function nextfloat(f::Union{Float16,Float32,Float64}, d::Integer)
558558
fu = fumax
559559
else
560560
du = da % U
561-
if xor(fneg, dneg)
561+
if fneg dneg
562562
if du > fu
563563
fu = min(fumax, du - fu)
564564
fneg = !fneg

base/gmp.jl

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 4 deletions
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
@@ -417,10 +417,10 @@ function frexp{T<:AbstractFloat}(x::T)
417417
if xe == 0 # x is subnormal
418418
x == 0 && return x, 0
419419
xs = xu & sign_mask(T)
420-
xu = xor(xu, xs)
420+
xu ⊻= xs
421421
m = leading_zeros(xu)-exponent_bits(T)
422422
xu <<= m
423-
xu = xor(xu, xs)
423+
xu ⊻= xs
424424
k = 1-m
425425
elseif xe == exponent_mask(T) # NaN or Inf
426426
return x, 0

base/operators.jl

Lines changed: 4 additions & 1 deletion
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.
@@ -1039,6 +1041,7 @@ export
10391041
,
10401042
,
10411043
,
1044+
,
10421045
colon,
10431046
hcat,
10441047
vcat,
@@ -1052,6 +1055,6 @@ import ..this_module: !, !=, xor, %, .%, ÷, .÷, &, *, +, -, .!=, .+, .-, .*, .
10521055
.>=, .\, .^, /, //, <, <:, <<, <=, ==, >, >=, >>, .>>, .<<, >>>,
10531056
<|, |>, \, ^, |, ~, !==, ===, >:, colon, hcat, vcat, hvcat, getindex, setindex!,
10541057
transpose, ctranspose,
1055-
, , , .≥, .≤, .≠, , ×, , , , , , , , , , ,
1058+
, , , .≥, .≤, .≠, , ×, , , , , , , , , , , ,
10561059

10571060
end

base/random.jl

Lines changed: 8 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)