diff --git a/NEWS.md b/NEWS.md index fe07847f836d7..3dfae718e95fc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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` ([#WHATAREBIRDS]). + + * `num2hex` and `hex2num` have been deprecated in favor of `reinterpret` combined with `parse`/`hex` ([#22088]). Command-line option changes diff --git a/base/deprecated.jl b/base/deprecated.jl index fce361c891a24..f5d39cbf23dec 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1913,6 +1913,9 @@ end @deprecate float(x::AbstractString) parse(Float64, x) @deprecate float(a::AbstractArray{<:AbstractString}) parse.(Float64, a) +# deprecate bits to bitstring +@deprecate bits(x) bitstring(x) + # issue #24167 @deprecate EnvHash EnvDict diff --git a/base/exports.jl b/base/exports.jl index 09fd49d701fb2..671af6fef777c 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -722,7 +722,7 @@ export Base64DecodePipe, startswith, bin, - bits, + bitstring, bytes2hex, chomp, chop, diff --git a/base/intfuncs.jl b/base/intfuncs.jl index e60408dce1f33..bfcf322bafdb5 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -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) diff --git a/base/operators.jl b/base/operators.jl index 6fdb836f227c4..60860e71b3d08 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -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). @@ -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). @@ -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" ``` diff --git a/doc/src/manual/integers-and-floating-point-numbers.md b/doc/src/manual/integers-and-floating-point-numbers.md index 5f0a66fae35ac..75dfabf19a7f4 100644 --- a/doc/src/manual/integers-and-floating-point-numbers.md +++ b/doc/src/manual/integers-and-floating-point-numbers.md @@ -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" ``` @@ -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" ``` diff --git a/test/intfuncs.jl b/test/intfuncs.jl index 16ecaeb3cea65..779ce240add9a 100644 --- a/test/intfuncs.jl +++ b/test/intfuncs.jl @@ -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] diff --git a/test/numbers.jl b/test/numbers.jl index d7aa0436b10c5..3f944f4823212 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -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)