Skip to content

Commit

Permalink
re-enable ndigits(::Bool, b) (fix #21919)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed May 18, 2017
1 parent 259daca commit d28135d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ function ndigits0znb(n::Integer, b::Integer)
end

ndigits0znb(n::Unsigned, b::Integer) = ndigits0znb(signed(n), b)
ndigits0znb(n::Bool, b::Integer) = n % Int

# The suffix "pb" stands for "positive base"
# TODO: allow b::Integer
Expand Down Expand Up @@ -400,6 +401,7 @@ end

ndigits0zpb(x::Base.BitSigned, b::Integer) = ndigits0zpb(unsigned(abs(x)), Int(b))
ndigits0zpb(x::Base.BitUnsigned, b::Integer) = ndigits0zpb(x, Int(b))
ndigits0zpb(x::Bool, b::Integer) = x % Int

# The suffix "0z" means that the output is 0 on input zero (cf. #16841)
"""
Expand Down
5 changes: 5 additions & 0 deletions test/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ end
@test ndigits(9, 0x2) == 4
@test ndigits(0x9, 0x2) == 4

# ndigits is defined for Bool
@test iszero([Base.ndigits0z(false, b) for b in [-20:-2;2:20]])
@test all(n -> n == 1, Base.ndigits0z(true, b) for b in [-20:-2;2:20])
@test all(n -> n == 1, ndigits(x, b) for b in [-20:-2;2:20] for x in [true, false])

@test bin('3') == "110011"
@test bin('3',7) == "0110011"
@test bin(3) == "11"
Expand Down

0 comments on commit d28135d

Please sign in to comment.