@@ -445,15 +445,18 @@ ndigits0znb(x::Unsigned, b::Integer) = ndigits0znb(-signed(fld(x, -b)), b) + (x
445
445
ndigits0znb (x:: Bool , b:: Integer ) = x % Int
446
446
447
447
# The suffix "pb" stands for "positive base"
448
- # TODO : allow b::Integer
449
- function ndigits0zpb (x:: Base.BitUnsigned , b:: Int )
448
+ function ndigits0zpb (x:: Integer , b:: Integer )
450
449
# precondition: b > 1
451
450
x == 0 && return 0
452
- b < 0 && return ndigits0znb (signed (x), b)
453
- b == 2 && return sizeof (x)<< 3 - leading_zeros (x)
454
- b == 8 && return (sizeof (x)<< 3 - leading_zeros (x) + 2 ) ÷ 3
455
- b == 16 && return sizeof (x)<< 1 - leading_zeros (x)>> 2
456
- b == 10 && return ndigits0z (x)
451
+ b = Int (b)
452
+ x = abs (x)
453
+ if x isa Base. BitInteger
454
+ x = unsigned (x)
455
+ b == 2 && return sizeof (x)<< 3 - leading_zeros (x)
456
+ b == 8 && return (sizeof (x)<< 3 - leading_zeros (x) + 2 ) ÷ 3
457
+ b == 16 && return sizeof (x)<< 1 - leading_zeros (x)>> 2
458
+ b == 10 && return ndigits0z (x)
459
+ end
457
460
458
461
d = 0
459
462
while x > typemax (Int)
@@ -471,8 +474,6 @@ function ndigits0zpb(x::Base.BitUnsigned, b::Int)
471
474
return d
472
475
end
473
476
474
- ndigits0zpb (x:: Base.BitSigned , b:: Integer ) = ndigits0zpb (unsigned (abs (x)), Int (b))
475
- ndigits0zpb (x:: Base.BitUnsigned , b:: Integer ) = ndigits0zpb (x, Int (b))
476
477
ndigits0zpb (x:: Bool , b:: Integer ) = x % Int
477
478
478
479
# The suffix "0z" means that the output is 0 on input zero (cf. #16841)
0 commit comments