From 8144c9a74c7d7e1a609fe20a6b233917f5658156 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sat, 6 Jan 2018 13:04:01 -0800 Subject: [PATCH] Deprecate ~ to !. --- base/bitarray.jl | 5 ----- base/bool.jl | 1 - base/deprecated.jl | 12 ++++++++++++ base/gmp.jl | 3 +-- base/int.jl | 7 ------- doc/src/base/math.md | 1 - doc/src/base/punctuation.md | 2 +- doc/src/manual/mathematical-operations.md | 8 ++++---- doc/src/manual/noteworthy-differences.md | 2 +- 9 files changed, 19 insertions(+), 22 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 8ced43ce1b3d3..bd190680d8f9e 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -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} @@ -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) diff --git a/base/bool.jl b/base/bool.jl index 135390cdf9859..8fa374692aad8 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -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) diff --git a/base/deprecated.jl b/base/deprecated.jl index 3b828b81ecaad..927b52854fca3 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2887,6 +2887,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) diff --git a/base/gmp.jl b/base/gmp.jl index f796dbdc4c6ab..3f00ff46016a6 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -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, @@ -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) diff --git a/base/int.jl b/base/int.jl index adffb34e04444..5a0ef1f5c9aa3 100644 --- a/base/int.jl +++ b/base/int.jl @@ -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) @@ -270,12 +269,6 @@ false ``` """ (!)(x::BitInteger) = not_int(x) -""" - ~(x) - -Bitwise not. -""" -(~)(x::BitInteger) = !x """ &(x, y) diff --git a/doc/src/base/math.md b/doc/src/base/math.md index 6b8cbf0bdaa7f..8a449e1fc9477 100644 --- a/doc/src/base/math.md +++ b/doc/src/base/math.md @@ -44,7 +44,6 @@ Base.:(<=) Base.:(>) Base.:(>=) Base.cmp -Base.:(~) Base.:(&) Base.:(|) Base.xor diff --git a/doc/src/base/punctuation.md b/doc/src/base/punctuation.md index 13fab22b8d277..92fd8d9d30f8e 100644 --- a/doc/src/base/punctuation.md +++ b/doc/src/base/punctuation.md @@ -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)) | diff --git a/doc/src/manual/mathematical-operations.md b/doc/src/manual/mathematical-operations.md index b539efbe3d0e5..f06a80f83c201 100644 --- a/doc/src/manual/mathematical-operations.md +++ b/doc/src/manual/mathematical-operations.md @@ -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) | @@ -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 @@ -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 ``` diff --git a/doc/src/manual/noteworthy-differences.md b/doc/src/manual/noteworthy-differences.md index 5874e57dbde86..e601d94a558b1 100644 --- a/doc/src/manual/noteworthy-differences.md +++ b/doc/src/manual/noteworthy-differences.md @@ -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