Skip to content

Commit

Permalink
Deprecate ~ to !.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 committed Jan 8, 2018
1 parent 712063e commit 834bac6
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 22 deletions.
5 changes: 0 additions & 5 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,6 @@ function broadcast(::typeof(!), B::BitArray)
end
return C
end
broadcast(::typeof(~), B::BitArray) = broadcast(!, B) # TODO deprecate



"""
flipbits!(B::BitArray{N}) -> BitArray{N}
Expand Down Expand Up @@ -1692,13 +1689,11 @@ maximum(B::BitArray) = isempty(B) ? throw(ArgumentError("argument must be non-em
# instead of looping bit-by-bit.

map(::typeof(!), A::BitArray) = bit_map!(!, similar(A), A)
map(::typeof(~), A::BitArray) = map(!, A) # TODO deprecate
map(::typeof(zero), A::BitArray) = fill!(similar(A), false)
map(::typeof(one), A::BitArray) = fill!(similar(A), true)
map(::typeof(identity), A::BitArray) = copy(A)

map!(::typeof(!), dest::BitArray, A::BitArray) = bit_map!(!, dest, A)
map!(::typeof(~), dest::BitArray, A::BitArray) = map(!, dest, A) # TODO deprecate

map!(::typeof(zero), dest::BitArray, A::BitArray) = fill!(dest, false)
map!(::typeof(one), dest::BitArray, A::BitArray) = fill!(dest, true)
Expand Down
1 change: 0 additions & 1 deletion base/bool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function !(x::Bool)
return not_int(x)
end

(~)(x::Bool) = !x
(&)(x::Bool, y::Bool) = and_int(x, y)
(|)(x::Bool, y::Bool) = or_int(x, y)

Expand Down
12 changes: 12 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,18 @@ workspace() = error("`workspace()` is discontinued, consider Revise.jl for an al
@deprecate Ref(x::Ptr) Ref(x, 1)
@deprecate Ref(x::Ref) x # or perhaps, `convert(Ref, x)`

# merge ~ into !
@deprecate map(::typeof(~), A::BitArray) map(!, A)
@deprecate map!(::typeof(~), dest::BitArray, A::BitArray) map(!, dest, A)
@deprecate broadcast(::typeof(~), B::BitArray) broadcast(!, B)
@deprecate (~)(x::Bool) !x
@deprecate (~)(n::Integer) !n
@deprecate (~)(x::BitInteger) !x
@eval Base.GMP begin
import Base: ~
@deprecate (~)(x::BigInt) !x
end

# PR #25184. Use getproperty instead of getindex for Factorizations
function getindex(F::Factorization, s::Symbol)
depwarn("`F[:$s]` is deprecated, use `F.$s` instead.", :getindex)
Expand Down
3 changes: 1 addition & 2 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module GMP

export BigInt

import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (!), (&), (|), xor,
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,
Expand Down Expand Up @@ -467,7 +467,6 @@ end
# unary ops
(-)(x::BigInt) = MPZ.neg(x)
(!)(x::BigInt) = MPZ.com(x)
(~)(x::BigInt) = !x

<<(x::BigInt, c::UInt) = c == 0 ? x : MPZ.mul_2exp(x, c)
>>(x::BigInt, c::UInt) = c == 0 ? x : MPZ.fdiv_q_2exp(x, c)
Expand Down
7 changes: 0 additions & 7 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ abs(x::Unsigned) = x
abs(x::Signed) = flipsign(x,x)

!(n::Integer) = -n-1
~(n::Integer) = !n

unsigned(x::BitSigned) = reinterpret(typeof(convert(Unsigned, zero(x))), x)
unsigned(x::Bool) = convert(Unsigned, x)
Expand Down Expand Up @@ -270,12 +269,6 @@ false
```
"""
(!)(x::BitInteger) = not_int(x)
"""
~(x)
Bitwise not.
"""
(~)(x::BitInteger) = !x

"""
&(x, y)
Expand Down
8 changes: 4 additions & 4 deletions doc/src/manual/mathematical-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ are supported on all primitive integer types:

| Expression | Name |
|:---------- |:------------------------------------------------------------------------ |
| `~x` | bitwise not |
| `!x` | bitwise not |
| `x & y` | bitwise and |
| `x \| y` | bitwise or |
| `x ⊻ y` | bitwise xor (exclusive or) |
Expand All @@ -66,7 +66,7 @@ are supported on all primitive integer types:
Here are some examples with bitwise operators:

```jldoctest
julia> ~123
julia> !123
-124
julia> 123 & 234
Expand All @@ -81,10 +81,10 @@ julia> 123 ⊻ 234
julia> xor(123, 234)
145
julia> ~UInt32(123)
julia> !UInt32(123)
0xffffff84
julia> ~UInt8(123)
julia> !UInt8(123)
0x84
```

Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/noteworthy-differences.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ For users coming to Julia from R, these are some noteworthy differences:
leading 0s. For example, `0x0` and `0x00` have type [`UInt8`](@ref), `0x000` and `0x0000` have type
[`UInt16`](@ref), then literals with 5 to 8 hex digits have type `UInt32`, 9 to 16 hex digits type
`UInt64` and 17 to 32 hex digits type `UInt128`. This needs to be taken into account when defining
hexadecimal masks, for example `~0xf == 0xf0` is very different from `~0x000f == 0xfff0`. 64 bit `Float64`
hexadecimal masks, for example `!0xf == 0xf0` is very different from `!0x000f == 0xfff0`. 64 bit `Float64`
and 32 bit [`Float32`](@ref) bit literals are expressed as `1.0` and `1.0f0` respectively. Floating point
literals are rounded (and not promoted to the `BigFloat` type) if they can not be exactly represented.
Floating point literals are closer in behavior to C/C++. Octal (prefixed with `0o`) and binary
Expand Down
1 change: 0 additions & 1 deletion doc/src/stdlib/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Base.:(<=)
Base.:(>)
Base.:(>=)
Base.cmp
Base.:(~)
Base.:(&)
Base.:(|)
Base.xor
Expand Down
2 changes: 1 addition & 1 deletion doc/src/stdlib/punctuation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Extended documentation for mathematical symbols & functions is [here](@ref math-
| `` | bitwise xor operator |
| `*` | multiply, or matrix multiply |
| `()` | the empty tuple |
| `~` | bitwise not operator |
| `!` | bitwise not operator |
| `\` | backslash operator |
| `'` | complex transpose operator Aᴴ |
| `a[]` | array indexing (calling [`getindex`](@ref) or [`setindex!`](@ref)) |
Expand Down

0 comments on commit 834bac6

Please sign in to comment.