Skip to content

Commit

Permalink
Deprecate bits to bitstring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 committed Oct 23, 2017
1 parent 175f7a1 commit 63e696a
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 35 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,9 @@ Deprecated or removed
`ReinterpretArray`. The three argument form of `reinterpret` that implicitly reshapes
has been deprecated ([#23750]).

* `num2hex` and `hex2num` have been deprecated in favor of `reinterpret` combined with `parse`/`hex`
([#22088])
* `bits` has been deprecated in favor of `bitstring` ([#24281], [#24263]).

* `num2hex` and `hex2num` have been deprecated in favor of `reinterpret` combined with `parse`/`hex` ([#22088]).


Command-line option changes
Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,9 @@ end
@deprecate float(x::AbstractString) parse(Float64, x)
@deprecate float(a::AbstractArray{<:AbstractString}) parse.(Float64, a)

# deprecate bits to bitstring (#24263, #24281)
@deprecate bits bitstring

# issue #24167
@deprecate EnvHash EnvDict

Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ export
Base64DecodePipe,
startswith,
bin,
bits,
bitstring,
bytes2hex,
chomp,
chop,
Expand Down
18 changes: 9 additions & 9 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -708,26 +708,26 @@ julia> dec(20, 3)
dec

"""
bits(n)
bitstring(n)
A string giving the literal bit representation of a number.
# Examples
```jldoctest
julia> bits(4)
julia> bitstring(4)
"0000000000000000000000000000000000000000000000000000000000000100"
julia> bits(2.2)
julia> bitstring(2.2)
"0100000000000001100110011001100110011001100110011001100110011010"
```
"""
function bits end
function bitstring end

bits(x::Union{Bool,Int8,UInt8}) = bin(reinterpret(UInt8,x),8)
bits(x::Union{Int16,UInt16,Float16}) = bin(reinterpret(UInt16,x),16)
bits(x::Union{Char,Int32,UInt32,Float32}) = bin(reinterpret(UInt32,x),32)
bits(x::Union{Int64,UInt64,Float64}) = bin(reinterpret(UInt64,x),64)
bits(x::Union{Int128,UInt128}) = bin(reinterpret(UInt128,x),128)
bitstring(x::Union{Bool,Int8,UInt8}) = bin(reinterpret(UInt8,x),8)
bitstring(x::Union{Int16,UInt16,Float16}) = bin(reinterpret(UInt16,x),16)
bitstring(x::Union{Char,Int32,UInt32,Float32}) = bin(reinterpret(UInt32,x),32)
bitstring(x::Union{Int64,UInt64,Float64}) = bin(reinterpret(UInt64,x),64)
bitstring(x::Union{Int128,UInt128}) = bin(reinterpret(UInt128,x),128)

"""
digits([T<:Integer], n::Integer, base::T=10, pad::Integer=1)
Expand Down
16 changes: 8 additions & 8 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,10 @@ this is equivalent to `x >> -n`.
julia> Int8(3) << 2
12
julia> bits(Int8(3))
julia> bitstring(Int8(3))
"00000011"
julia> bits(Int8(12))
julia> bitstring(Int8(12))
"00001100"
```
See also [`>>`](@ref), [`>>>`](@ref).
Expand All @@ -548,19 +548,19 @@ right by `n` bits, where `n >= 0`, filling with `0`s if `x >= 0`, `1`s if `x <
julia> Int8(13) >> 2
3
julia> bits(Int8(13))
julia> bitstring(Int8(13))
"00001101"
julia> bits(Int8(3))
julia> bitstring(Int8(3))
"00000011"
julia> Int8(-14) >> 2
-4
julia> bits(Int8(-14))
julia> bitstring(Int8(-14))
"11110010"
julia> bits(Int8(-4))
julia> bitstring(Int8(-4))
"11111100"
```
See also [`>>>`](@ref), [`<<`](@ref).
Expand Down Expand Up @@ -589,10 +589,10 @@ For [`Unsigned`](@ref) integer types, this is equivalent to [`>>`](@ref). For
julia> Int8(-14) >>> 2
60
julia> bits(Int8(-14))
julia> bitstring(Int8(-14))
"11110010"
julia> bits(Int8(60))
julia> bitstring(Int8(60))
"00111100"
```
Expand Down
10 changes: 5 additions & 5 deletions doc/src/manual/integers-and-floating-point-numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ can be seen using the `bits` function: :
julia> 0.0 == -0.0
true
julia> bits(0.0)
julia> bitstring(0.0)
"0000000000000000000000000000000000000000000000000000000000000000"
julia> bits(-0.0)
julia> bitstring(-0.0)
"1000000000000000000000000000000000000000000000000000000000000000"
```

Expand Down Expand Up @@ -443,13 +443,13 @@ julia> nextfloat(x)
julia> prevfloat(x)
1.2499999f0
julia> bits(prevfloat(x))
julia> bitstring(prevfloat(x))
"00111111100111111111111111111111"
julia> bits(x)
julia> bitstring(x)
"00111111101000000000000000000000"
julia> bits(nextfloat(x))
julia> bitstring(nextfloat(x))
"00111111101000000000000000000001"
```

Expand Down
2 changes: 1 addition & 1 deletion doc/src/stdlib/numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Base.oct
Base.base
Base.digits
Base.digits!
Base.bits
Base.bitstring
Base.parse(::Type, ::Any, ::Any)
Base.tryparse
Base.big
Expand Down
8 changes: 4 additions & 4 deletions test/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ end

@test base(2, 5, 7) == "0000101"

@test bits(Int16(3)) == "0000000000000011"
@test bits('3') == "00000000000000000000000000110011"
@test bits(1035) == (Int == Int32 ? "00000000000000000000010000001011" :
@test bitstring(Int16(3)) == "0000000000000011"
@test bitstring('3') == "00000000000000000000000000110011"
@test bitstring(1035) == (Int == Int32 ? "00000000000000000000010000001011" :
"0000000000000000000000000000000000000000000000000000010000001011")
@test bits(Int128(3)) == "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011"
@test bitstring(Int128(3)) == "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011"
end
@testset "digits/base" begin
@test digits(4, 2) == [0, 0, 1]
Expand Down
4 changes: 2 additions & 2 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2369,8 +2369,8 @@ end
@test -0.0 + false === -0.0

@testset "issue #5881" begin
@test bits(true) == "00000001"
@test bits(false) == "00000000"
@test bitstring(true) == "00000001"
@test bitstring(false) == "00000000"
end
@testset "edge cases of intrinsics" begin
let g() = sqrt(-1.0)
Expand Down
6 changes: 3 additions & 3 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ end
i = rand(I) >> 1 # test large values below
hi, lo = Base.splitprec(T, i)
@test widen(hi) + widen(lo) == i
@test endswith(bits(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
@test endswith(bitstring(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
end
for (I, T) in ((Int16, Float16), (Int32, Float32), (Int64, Float64))
x = T(typemax(I))
Δi = ceil(I, eps(x))
for i = typemax(I)-2Δi:typemax(I)-Δi
hi, lo = Base.splitprec(T, i)
@test widen(hi) + widen(lo) == i
@test endswith(bits(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
@test endswith(bitstring(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
end
for i = typemin(I):typemin(I)+Δi
hi, lo = Base.splitprec(T, i)
@test widen(hi) + widen(lo) == i
@test endswith(bits(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
@test endswith(bitstring(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
end
end

Expand Down

0 comments on commit 63e696a

Please sign in to comment.