Skip to content

Commit 3b94a9e

Browse files
Sacha0JeffBezanson
authored andcommitted
Deprecate bits to bitstring. (#24281)
1 parent 88f7729 commit 3b94a9e

10 files changed

+39
-35
lines changed

NEWS.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,9 @@ Deprecated or removed
576576
`ReinterpretArray`. The three argument form of `reinterpret` that implicitly reshapes
577577
has been deprecated ([#23750]).
578578

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

582583

583584
Command-line option changes

base/deprecated.jl

+3
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,9 @@ end
20492049
@deprecate float(x::AbstractString) parse(Float64, x)
20502050
@deprecate float(a::AbstractArray{<:AbstractString}) parse.(Float64, a)
20512051

2052+
# deprecate bits to bitstring (#24263, #24281)
2053+
@deprecate bits bitstring
2054+
20522055
# issue #24167
20532056
@deprecate EnvHash EnvDict
20542057

base/exports.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ export
721721
Base64DecodePipe,
722722
startswith,
723723
bin,
724-
bits,
724+
bitstring,
725725
bytes2hex,
726726
chomp,
727727
chop,

base/intfuncs.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -708,26 +708,26 @@ julia> dec(20, 3)
708708
dec
709709

710710
"""
711-
bits(n)
711+
bitstring(n)
712712
713713
A string giving the literal bit representation of a number.
714714
715715
# Examples
716716
```jldoctest
717-
julia> bits(4)
717+
julia> bitstring(4)
718718
"0000000000000000000000000000000000000000000000000000000000000100"
719719
720-
julia> bits(2.2)
720+
julia> bitstring(2.2)
721721
"0100000000000001100110011001100110011001100110011001100110011010"
722722
```
723723
"""
724-
function bits end
724+
function bitstring end
725725

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

732732
"""
733733
digits([T<:Integer], n::Integer, base::T=10, pad::Integer=1)

base/operators.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,10 @@ this is equivalent to `x >> -n`.
518518
julia> Int8(3) << 2
519519
12
520520
521-
julia> bits(Int8(3))
521+
julia> bitstring(Int8(3))
522522
"00000011"
523523
524-
julia> bits(Int8(12))
524+
julia> bitstring(Int8(12))
525525
"00001100"
526526
```
527527
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 <
548548
julia> Int8(13) >> 2
549549
3
550550
551-
julia> bits(Int8(13))
551+
julia> bitstring(Int8(13))
552552
"00001101"
553553
554-
julia> bits(Int8(3))
554+
julia> bitstring(Int8(3))
555555
"00000011"
556556
557557
julia> Int8(-14) >> 2
558558
-4
559559
560-
julia> bits(Int8(-14))
560+
julia> bitstring(Int8(-14))
561561
"11110010"
562562
563-
julia> bits(Int8(-4))
563+
julia> bitstring(Int8(-4))
564564
"11111100"
565565
```
566566
See also [`>>>`](@ref), [`<<`](@ref).
@@ -589,10 +589,10 @@ For [`Unsigned`](@ref) integer types, this is equivalent to [`>>`](@ref). For
589589
julia> Int8(-14) >>> 2
590590
60
591591
592-
julia> bits(Int8(-14))
592+
julia> bitstring(Int8(-14))
593593
"11110010"
594594
595-
julia> bits(Int8(60))
595+
julia> bitstring(Int8(60))
596596
"00111100"
597597
```
598598

doc/src/manual/integers-and-floating-point-numbers.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ can be seen using the `bits` function: :
311311
julia> 0.0 == -0.0
312312
true
313313
314-
julia> bits(0.0)
314+
julia> bitstring(0.0)
315315
"0000000000000000000000000000000000000000000000000000000000000000"
316316
317-
julia> bits(-0.0)
317+
julia> bitstring(-0.0)
318318
"1000000000000000000000000000000000000000000000000000000000000000"
319319
```
320320

@@ -443,13 +443,13 @@ julia> nextfloat(x)
443443
julia> prevfloat(x)
444444
1.2499999f0
445445
446-
julia> bits(prevfloat(x))
446+
julia> bitstring(prevfloat(x))
447447
"00111111100111111111111111111111"
448448
449-
julia> bits(x)
449+
julia> bitstring(x)
450450
"00111111101000000000000000000000"
451451
452-
julia> bits(nextfloat(x))
452+
julia> bitstring(nextfloat(x))
453453
"00111111101000000000000000000001"
454454
```
455455

doc/src/stdlib/numbers.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Base.oct
4747
Base.base
4848
Base.digits
4949
Base.digits!
50-
Base.bits
50+
Base.bitstring
5151
Base.parse(::Type, ::Any, ::Any)
5252
Base.tryparse
5353
Base.big

test/intfuncs.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ end
133133

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

136-
@test bits(Int16(3)) == "0000000000000011"
137-
@test bits('3') == "00000000000000000000000000110011"
138-
@test bits(1035) == (Int == Int32 ? "00000000000000000000010000001011" :
136+
@test bitstring(Int16(3)) == "0000000000000011"
137+
@test bitstring('3') == "00000000000000000000000000110011"
138+
@test bitstring(1035) == (Int == Int32 ? "00000000000000000000010000001011" :
139139
"0000000000000000000000000000000000000000000000000000010000001011")
140-
@test bits(Int128(3)) == "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011"
140+
@test bitstring(Int128(3)) == "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011"
141141
end
142142
@testset "digits/base" begin
143143
@test digits(4, 2) == [0, 0, 1]

test/numbers.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -2369,8 +2369,8 @@ end
23692369
@test -0.0 + false === -0.0
23702370

23712371
@testset "issue #5881" begin
2372-
@test bits(true) == "00000001"
2373-
@test bits(false) == "00000000"
2372+
@test bitstring(true) == "00000001"
2373+
@test bitstring(false) == "00000000"
23742374
end
23752375
@testset "edge cases of intrinsics" begin
23762376
let g() = sqrt(-1.0)

test/ranges.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ end
6868
i = rand(I) >> 1 # test large values below
6969
hi, lo = Base.splitprec(T, i)
7070
@test widen(hi) + widen(lo) == i
71-
@test endswith(bits(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
71+
@test endswith(bitstring(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
7272
end
7373
for (I, T) in ((Int16, Float16), (Int32, Float32), (Int64, Float64))
7474
x = T(typemax(I))
7575
Δi = ceil(I, eps(x))
7676
for i = typemax(I)-2Δi:typemax(I)-Δi
7777
hi, lo = Base.splitprec(T, i)
7878
@test widen(hi) + widen(lo) == i
79-
@test endswith(bits(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
79+
@test endswith(bitstring(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
8080
end
8181
for i = typemin(I):typemin(I)+Δi
8282
hi, lo = Base.splitprec(T, i)
8383
@test widen(hi) + widen(lo) == i
84-
@test endswith(bits(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
84+
@test endswith(bitstring(hi), repeat('0', Base.Math.significand_bits(T) ÷ 2))
8585
end
8686
end
8787

0 commit comments

Comments
 (0)