Skip to content

Commit

Permalink
Merge pull request #22838 from JuliaLang/rf/fix-ndigits-0
Browse files Browse the repository at this point in the history
Base.ndigits0z(0, b) must return 0 (fix #22837)
  • Loading branch information
StefanKarpinski committed Jul 18, 2017
2 parents f77d4cf + 33ffc86 commit 88435c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ ndigits0znb(x::Bool, b::Integer) = x % Int
# TODO: allow b::Integer
function ndigits0zpb(x::Base.BitUnsigned, b::Int)
# precondition: b > 1
x == 0 && return 0
b < 0 && return ndigits0znb(signed(x), b)
b == 2 && return sizeof(x)<<3 - leading_zeros(x)
b == 8 && return (sizeof(x)<<3 - leading_zeros(x) + 2) ÷ 3
Expand Down
5 changes: 5 additions & 0 deletions test/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,8 @@ end

# issue #15911
@inferred string(1)

# issue #22837
for b in [-100:-2; 2:100;]
@test Base.ndigits0z(0, b) == 0
end

0 comments on commit 88435c0

Please sign in to comment.