Skip to content

Commit 4415011

Browse files
committed
Replace all ~ calls with ! in base/.
1 parent def2bb3 commit 4415011

23 files changed

+96
-90
lines changed

base/atomics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function atomic_and! end
203203
204204
Atomically bitwise-nand (not-and) `x` with `val`
205205
206-
Performs `x[] = ~(x[] & val)` atomically. Returns the **old** value.
206+
Performs `x[] = !(x[] & val)` atomically. Returns the **old** value.
207207
208208
For further details, see LLVM's `atomicrmw nand` instruction.
209209

base/bitarray.jl

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ IndexStyle(::Type{<:BitArray}) = IndexLinear()
8181

8282
## aux functions ##
8383

84-
const _msk64 = ~UInt64(0)
84+
const _msk64 = !UInt64(0)
8585
@inline _div64(l) = l >> 6
8686
@inline _mod64(l) = l & 63
8787
@inline _msk_end(l::Integer) = _msk64 >>> _mod64(-l)
@@ -94,7 +94,7 @@ function glue_src_bitchunks(src::Vector{UInt64}, k::Int, ks1::Int, msk_s0::UInt6
9494
@inbounds begin
9595
chunk = ((src[k] & msk_s0) >>> ls0)
9696
if ks1 > k && ls0 > 0
97-
chunk_n = (src[k + 1] & ~msk_s0)
97+
chunk_n = (src[k + 1] & !msk_s0)
9898
chunk |= (chunk_n << (64 - ls0))
9999
end
100100
end
@@ -117,20 +117,20 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64},
117117

118118
u = _msk64
119119
if delta_kd == 0
120-
msk_d0 = ~(u << ld0) | (u << (ld1+1))
120+
msk_d0 = !(u << ld0) | (u << (ld1+1))
121121
else
122-
msk_d0 = ~(u << ld0)
122+
msk_d0 = !(u << ld0)
123123
msk_d1 = (u << (ld1+1))
124124
end
125125
if delta_ks == 0
126-
msk_s0 = (u << ls0) & ~(u << (ls1+1))
126+
msk_s0 = (u << ls0) & !(u << (ls1+1))
127127
else
128128
msk_s0 = (u << ls0)
129129
end
130130

131131
chunk_s0 = glue_src_bitchunks(src, ks0, ks1, msk_s0, ls0)
132132

133-
dest[kd0] = (dest[kd0] & msk_d0) | ((chunk_s0 << ld0) & ~msk_d0)
133+
dest[kd0] = (dest[kd0] & msk_d0) | ((chunk_s0 << ld0) & !msk_d0)
134134

135135
delta_kd == 0 && return
136136

@@ -152,7 +152,7 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64},
152152

153153
chunk_s = (chunk_s0 >>> (64 - ld0)) | (chunk_s1 << ld0)
154154

155-
dest[kd1] = (dest[kd1] & msk_d1) | (chunk_s & ~msk_d1)
155+
dest[kd1] = (dest[kd1] & msk_d1) | (chunk_s & !msk_d1)
156156

157157
return
158158
end
@@ -177,24 +177,24 @@ function copy_chunks_rtol!(chunks::Vector{UInt64}, pos_d::Integer, pos_s::Intege
177177
delta_ks = ks1 - ks0
178178

179179
if delta_kd == 0
180-
msk_d0 = ~(u << ld0) | (u << (ld1+1))
180+
msk_d0 = !(u << ld0) | (u << (ld1+1))
181181
else
182-
msk_d0 = ~(u << ld0)
182+
msk_d0 = !(u << ld0)
183183
msk_d1 = (u << (ld1+1))
184184
end
185185
if delta_ks == 0
186-
msk_s0 = (u << ls0) & ~(u << (ls1+1))
186+
msk_s0 = (u << ls0) & !(u << (ls1+1))
187187
else
188188
msk_s0 = (u << ls0)
189189
end
190190

191-
chunk_s0 = glue_src_bitchunks(chunks, ks0, ks1, msk_s0, ls0) & ~(u << s)
192-
chunks[kd0] = (chunks[kd0] & msk_d0) | ((chunk_s0 << ld0) & ~msk_d0)
191+
chunk_s0 = glue_src_bitchunks(chunks, ks0, ks1, msk_s0, ls0) & !(u << s)
192+
chunks[kd0] = (chunks[kd0] & msk_d0) | ((chunk_s0 << ld0) & !msk_d0)
193193

194194
if delta_kd != 0
195195
chunk_s = (chunk_s0 >>> (64 - ld0))
196196

197-
chunks[kd1] = (chunks[kd1] & msk_d1) | (chunk_s & ~msk_d1)
197+
chunks[kd1] = (chunks[kd1] & msk_d1) | (chunk_s & !msk_d1)
198198
end
199199

200200
left -= s
@@ -212,10 +212,10 @@ function fill_chunks!(Bc::Array{UInt64}, x::Bool, pos::Integer, numbits::Integer
212212

213213
u = _msk64
214214
if k1 == k0
215-
msk0 = (u << l0) & ~(u << (l1+1))
215+
msk0 = (u << l0) & !(u << (l1+1))
216216
else
217217
msk0 = (u << l0)
218-
msk1 = ~(u << (l1+1))
218+
msk1 = !(u << (l1+1))
219219
end
220220
@inbounds if x
221221
Bc[k0] |= msk0
@@ -224,11 +224,11 @@ function fill_chunks!(Bc::Array{UInt64}, x::Bool, pos::Integer, numbits::Integer
224224
end
225225
k1 > k0 && (Bc[k1] |= msk1)
226226
else
227-
Bc[k0] &= ~msk0
227+
Bc[k0] &= !msk0
228228
for k = k0+1:k1-1
229229
Bc[k] = 0
230230
end
231-
k1 > k0 && (Bc[k1] &= ~msk1)
231+
k1 > k0 && (Bc[k1] &= !msk1)
232232
end
233233
end
234234

@@ -253,10 +253,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool}
253253

254254
u = _msk64
255255
if delta_kd == 0
256-
msk_d0 = msk_d1 = ~(u << ld0) | (u << (ld1+1))
256+
msk_d0 = msk_d1 = !(u << ld0) | (u << (ld1+1))
257257
lt0 = ld1
258258
else
259-
msk_d0 = ~(u << ld0)
259+
msk_d0 = !(u << ld0)
260260
msk_d1 = (u << (ld1+1))
261261
lt0 = 63
262262
end
@@ -269,7 +269,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool}
269269
c |= (UInt64(C[ind]) << j)
270270
ind += 1
271271
end
272-
Bc[kd0] = (Bc[kd0] & msk_d0) | (c & ~msk_d0)
272+
Bc[kd0] = (Bc[kd0] & msk_d0) | (c & !msk_d0)
273273
bind += 1
274274
end
275275

@@ -306,7 +306,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool}
306306
c |= (UInt64(C[ind]) << j)
307307
ind += 1
308308
end
309-
Bc[kd1] = (Bc[kd1] & msk_d1) | (c & ~msk_d1)
309+
Bc[kd1] = (Bc[kd1] & msk_d1) | (c & !msk_d1)
310310
end
311311
end
312312

@@ -408,7 +408,7 @@ function copyto!(dest::BitArray, src::BitArray)
408408
destc[nc] = srcc[nc]
409409
else
410410
msk_s = _msk_end(src)
411-
msk_d = ~msk_s
411+
msk_d = !msk_s
412412
destc[nc] = (msk_d & destc[nc]) | (msk_s & srcc[nc])
413413
end
414414
end
@@ -634,7 +634,7 @@ end
634634
u = UInt64(1) << i2
635635
@inbounds begin
636636
c = Bc[i1]
637-
Bc[i1] = ifelse(x, c | u, c & ~u)
637+
Bc[i1] = ifelse(x, c | u, c & !u)
638638
end
639639
end
640640

@@ -676,7 +676,7 @@ function _unsafe_setindex!(B::BitArray, x, I::BitArray)
676676
end
677677
else
678678
for i = 1:length(Bc)
679-
Bc[i] &= ~Ic[i]
679+
Bc[i] &= !Ic[i]
680680
end
681681
end
682682
return B
@@ -705,7 +705,7 @@ function _unsafe_setindex!(B::BitArray, X::AbstractArray, I::BitArray)
705705
if Imsk & u != 0
706706
lx < c && throw_setindex_mismatch(X, c)
707707
@inbounds x = convert(Bool, X[c])
708-
C = ifelse(x, C | u, C & ~u)
708+
C = ifelse(x, C | u, C & !u)
709709
c += 1
710710
end
711711
u <<= 1
@@ -879,7 +879,7 @@ function insert!(B::BitVector, i::Integer, item)
879879
end
880880

881881
msk_aft = (_msk64 << j)
882-
msk_bef = ~msk_aft
882+
msk_bef = !msk_aft
883883
Bc[k] = (msk_bef & Bc[k]) | ((msk_aft & Bc[k]) << 1)
884884
B[i] = item
885885
B
@@ -889,7 +889,7 @@ function _deleteat!(B::BitVector, i::Integer)
889889
k, j = get_chunks_id(i)
890890

891891
msk_bef = _msk64 >>> (63 - j)
892-
msk_aft = ~msk_bef
892+
msk_aft = !msk_bef
893893
msk_bef >>>= 1
894894

895895
Bc = B.chunks
@@ -1088,23 +1088,26 @@ function (-)(B::BitArray)
10881088
end
10891089
broadcast(::typeof(sign), B::BitArray) = copy(B)
10901090

1091-
function broadcast(::typeof(~), B::BitArray)
1091+
function broadcast(::typeof(!), B::BitArray)
10921092
C = similar(B)
10931093
Bc = B.chunks
10941094
if !isempty(Bc)
10951095
Cc = C.chunks
10961096
for i = 1:length(Bc)
1097-
Cc[i] = ~Bc[i]
1097+
Cc[i] = !Bc[i]
10981098
end
10991099
Cc[end] &= _msk_end(B)
11001100
end
11011101
return C
11021102
end
1103+
broadcast(::typeof(~), B::BitArray) = broadcast(!, B) # TODO deprecate
1104+
1105+
11031106

11041107
"""
11051108
flipbits!(B::BitArray{N}) -> BitArray{N}
11061109
1107-
Performs a bitwise not operation on `B`. See [`~`](@ref).
1110+
Performs a bitwise not operation on `B`. See [`!`](@ref).
11081111
11091112
# Examples
11101113
```jldoctest
@@ -1123,7 +1126,7 @@ function flipbits!(B::BitArray)
11231126
Bc = B.chunks
11241127
@inbounds if !isempty(Bc)
11251128
for i = 1:length(Bc)
1126-
Bc[i] = ~Bc[i]
1129+
Bc[i] = !Bc[i]
11271130
end
11281131
Bc[end] &= _msk_end(B)
11291132
end
@@ -1162,7 +1165,7 @@ broadcast(::typeof(&), B::BitArray, x::Bool) = x ? copy(B) : falses(size(B))
11621165
broadcast(::typeof(&), x::Bool, B::BitArray) = broadcast(&, B, x)
11631166
broadcast(::typeof(|), B::BitArray, x::Bool) = x ? trues(size(B)) : copy(B)
11641167
broadcast(::typeof(|), x::Bool, B::BitArray) = broadcast(|, B, x)
1165-
broadcast(::typeof(xor), B::BitArray, x::Bool) = x ? .~B : copy(B)
1168+
broadcast(::typeof(xor), B::BitArray, x::Bool) = x ? .!B : copy(B)
11661169
broadcast(::typeof(xor), x::Bool, B::BitArray) = broadcast(xor, B, x)
11671170
for f in (:&, :|, :xor)
11681171
@eval begin
@@ -1471,7 +1474,7 @@ end
14711474

14721475
#findfirst(B::BitArray) = findnext(B, 1) ## defined in array.jl
14731476

1474-
# aux function: same as findnext(~B, start), but performed without temporaries
1477+
# aux function: same as findnext(!B, start), but performed without temporaries
14751478
function findnextnot(B::BitArray, start::Integer)
14761479
start > 0 || throw(BoundsError(B, start))
14771480
start > length(B) && return 0
@@ -1482,7 +1485,7 @@ function findnextnot(B::BitArray, start::Integer)
14821485

14831486
chunk_start = _div64(start-1)+1
14841487
within_chunk_start = _mod64(start-1)
1485-
mask = ~(_msk64 << within_chunk_start)
1488+
mask = !(_msk64 << within_chunk_start)
14861489

14871490
@inbounds if chunk_start < l
14881491
if Bc[chunk_start] | mask != _msk64
@@ -1557,7 +1560,7 @@ function findprevnot(B::BitArray, start::Integer)
15571560
Bc = B.chunks
15581561

15591562
chunk_start = _div64(start-1)+1
1560-
mask = ~_msk_end(start)
1563+
mask = !_msk_end(start)
15611564

15621565
@inbounds begin
15631566
if Bc[chunk_start] | mask != _msk64
@@ -1688,24 +1691,27 @@ maximum(B::BitArray) = isempty(B) ? throw(ArgumentError("argument must be non-em
16881691
# arrays since there can be a 64x speedup by working at the level of Int64
16891692
# instead of looping bit-by-bit.
16901693

1691-
map(::Union{typeof(~), typeof(!)}, A::BitArray) = bit_map!(~, similar(A), A)
1694+
map(::typeof(!), A::BitArray) = bit_map!(!, similar(A), A)
1695+
map(::typeof(~), A::BitArray) = map(!, A) # TODO deprecate
16921696
map(::typeof(zero), A::BitArray) = fill!(similar(A), false)
16931697
map(::typeof(one), A::BitArray) = fill!(similar(A), true)
16941698
map(::typeof(identity), A::BitArray) = copy(A)
16951699

1696-
map!(::Union{typeof(~), typeof(!)}, dest::BitArray, A::BitArray) = bit_map!(~, dest, A)
1700+
map!(::typeof(!), dest::BitArray, A::BitArray) = bit_map!(!, dest, A)
1701+
map!(::typeof(~), dest::BitArray, A::BitArray) = map(!, dest, A) # TODO deprecate
1702+
16971703
map!(::typeof(zero), dest::BitArray, A::BitArray) = fill!(dest, false)
16981704
map!(::typeof(one), dest::BitArray, A::BitArray) = fill!(dest, true)
16991705
map!(::typeof(identity), dest::BitArray, A::BitArray) = copyto!(dest, A)
17001706

17011707
for (T, f) in ((:(Union{typeof(&), typeof(*), typeof(min)}), :(&)),
17021708
(:(Union{typeof(|), typeof(max)}), :(|)),
17031709
(:(Union{typeof(xor), typeof(!=)}), :xor),
1704-
(:(Union{typeof(>=), typeof(^)}), :((p, q) -> p | ~q)),
1705-
(:(typeof(<=)), :((p, q) -> ~p | q)),
1706-
(:(typeof(==)), :((p, q) -> ~xor(p, q))),
1707-
(:(typeof(<)), :((p, q) -> ~p & q)),
1708-
(:(typeof(>)), :((p, q) -> p & ~q)))
1710+
(:(Union{typeof(>=), typeof(^)}), :((p, q) -> p | !q)),
1711+
(:(typeof(<=)), :((p, q) -> !p | q)),
1712+
(:(typeof(==)), :((p, q) -> !xor(p, q))),
1713+
(:(typeof(<)), :((p, q) -> !p & q)),
1714+
(:(typeof(>)), :((p, q) -> p & !q)))
17091715
@eval map(::$T, A::BitArray, B::BitArray) = bit_map!($f, similar(A), A, B)
17101716
@eval map!(::$T, dest::BitArray, A::BitArray, B::BitArray) = bit_map!($f, dest, A, B)
17111717
end

base/bitset.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ intersect(s1::BitSet, s2::BitSet) =
265265

266266
intersect!(s1::BitSet, s2::BitSet) = _matched_map!(&, s1, s2)
267267

268-
setdiff!(s1::BitSet, s2::BitSet) = _matched_map!((p, q) -> p & ~q, s1, s2)
268+
setdiff!(s1::BitSet, s2::BitSet) = _matched_map!((p, q) -> p & !q, s1, s2)
269269

270270
symdiff!(s::BitSet, ns) = foldl(int_symdiff!, s, ns)
271271

base/checked.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ end
148148
if BrokenUnsignedInt != Union{}
149149
function add_with_overflow(x::T, y::T) where T<:BrokenUnsignedInt
150150
# x + y > typemax(T)
151-
# Note: ~y == -y-1
152-
x + y, x > ~y
151+
# Note: !y == -y-1
152+
x + y, x > !y
153153
end
154154
end
155155

base/deprecated.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,8 @@ import .Math: clamp
796796
@deprecate(!(B::BitArray), .!B) # parens for #20541
797797

798798
# Deprecate vectorized ~
799-
@deprecate ~(A::AbstractArray) .~A
800-
@deprecate ~(B::BitArray) .~B
799+
@deprecate ~(A::AbstractArray) .!A
800+
@deprecate ~(B::BitArray) .!B
801801

802802
function Math.frexp(A::Array{<:AbstractFloat})
803803
depwarn(string("`frexp(x::Array)` is discontinued. Though not a direct replacement, ",

base/float.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function Float64(x::UInt128)
8282
else
8383
y = ((x >> (n-54)) % UInt64) & 0x001f_ffff_ffff_ffff # keep 1 extra bit
8484
y = (y+1)>>1 # round, ties up (extra leading bit in case of next exponent)
85-
y &= ~UInt64(trailing_zeros(x) == (n-54)) # fix last bit to round to even
85+
y &= !UInt64(trailing_zeros(x) == (n-54)) # fix last bit to round to even
8686
end
8787
d = ((n+1022) % UInt64) << 52
8888
reinterpret(Float64, d + y)
@@ -98,7 +98,7 @@ function Float64(x::Int128)
9898
else
9999
y = ((x >> (n-54)) % UInt64) & 0x001f_ffff_ffff_ffff # keep 1 extra bit
100100
y = (y+1)>>1 # round, ties up (extra leading bit in case of next exponent)
101-
y &= ~UInt64(trailing_zeros(x) == (n-54)) # fix last bit to round to even
101+
y &= !UInt64(trailing_zeros(x) == (n-54)) # fix last bit to round to even
102102
end
103103
d = ((n+1022) % UInt64) << 52
104104
reinterpret(Float64, s | d + y)
@@ -112,7 +112,7 @@ function Float32(x::UInt128)
112112
else
113113
y = ((x >> (n-25)) % UInt32) & 0x00ff_ffff # keep 1 extra bit
114114
y = (y+one(UInt32))>>1 # round, ties up (extra leading bit in case of next exponent)
115-
y &= ~UInt32(trailing_zeros(x) == (n-25)) # fix last bit to round to even
115+
y &= !UInt32(trailing_zeros(x) == (n-25)) # fix last bit to round to even
116116
end
117117
d = ((n+126) % UInt32) << 23
118118
reinterpret(Float32, d + y)
@@ -128,7 +128,7 @@ function Float32(x::Int128)
128128
else
129129
y = ((x >> (n-25)) % UInt32) & 0x00ff_ffff # keep 1 extra bit
130130
y = (y+one(UInt32))>>1 # round, ties up (extra leading bit in case of next exponent)
131-
y &= ~UInt32(trailing_zeros(x) == (n-25)) # fix last bit to round to even
131+
y &= !UInt32(trailing_zeros(x) == (n-25)) # fix last bit to round to even
132132
end
133133
d = ((n+126) % UInt32) << 23
134134
reinterpret(Float32, s | d + y)
@@ -177,7 +177,7 @@ function Float32(val::Float16)
177177
end
178178
sign = sign << 31
179179
exp = (-14 - n_bit + 127) << 23
180-
sig = ((sig & (~bit)) << n_bit) << (23 - 10)
180+
sig = ((sig & (!bit)) << n_bit) << (23 - 10)
181181
ret = sign | exp | sig
182182
end
183183
elseif exp == 0x1f
@@ -856,7 +856,7 @@ uinttype(::Type{Float64}) = UInt64
856856
uinttype(::Type{Float32}) = UInt32
857857
uinttype(::Type{Float16}) = UInt16
858858

859-
Base.iszero(x::Float16) = reinterpret(UInt16, x) & ~sign_mask(Float16) == 0x0000
859+
Base.iszero(x::Float16) = reinterpret(UInt16, x) & !sign_mask(Float16) == 0x0000
860860

861861
## Array operations on floating point numbers ##
862862

0 commit comments

Comments
 (0)