-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ndigits: check for invalid bases (fix #16766) #16841
Conversation
base/intfuncs.jl
Outdated
|
||
ndigits(x::Unsigned, b::Integer) = x==0 ? 1 : ndigits0z(x,Int(b)) | ||
ndigits(x::Unsigned) = x==0 ? 1 : ndigits0z(x) | ||
ndigits(x::Integer, b::Integer) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the function
form here
14c8e73
to
2222c59
Compare
Thanks for reviewing @tkelman, comments addressed. |
LGTM! The added comments are quite useful, thanks for those. |
I must admit that the "0z" suffix is not 100% clear for me, hence left uncommented! |
If keyword arguments didn't introduce too much overhead still, we could make the signature digits(n; base::Integer=10, min::Integer=1) That way you could do |
Do we agree on the idea that: |
Yes, that's the correct interpretation. |
2222c59
to
65e7d43
Compare
I pushed a new commit which renames |
65e7d43
to
ecd6480
Compare
Sorry this got neglected, could you rebase? |
ecd6480
to
cff9e1b
Compare
Updated, but please give me a couple more days before merging, I would like to squash and review once more (I can't continue working on it right now). |
cff9e1b
to
b1dd555
Compare
b1dd555
to
95a4888
Compare
Rebased, and I replaced my |
Great, LGTM. Anyone else have any thoughts? |
Let's get some votes on |
|
|
Needs a rebase. |
Should I wait till 0.6 is released before rebasing and hopefully merging? |
Yes, I'm afraid that since this includes user-visible changes, we'll have to wait at this point, so no point in rebasing before we branch release-0.6 from master. |
95a4888
to
288885d
Compare
15c6da9
to
1b7f40f
Compare
I rebased now, the travis errors are apparently independant. This is good to go on my side. |
base/intfuncs.jl
Outdated
ndigits0zpb(x::Base.BitSigned, b::Integer) = ndigits0zpb(unsigned(abs(x)), Int(b)) | ||
ndigits0zpb(x::Base.BitUnsigned, b::Integer) = ndigits0zpb(x, Int(b)) | ||
|
||
# The suffix "0z" means that the ouput is 0 on input zero (cf. #16841) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
1b7f40f
to
65002d7
Compare
base/intfuncs.jl
Outdated
|
||
# TODO (when keywords args are fast): rename to ndigits and make pad a keyword | ||
ndigits10(x::Integer, pad::Int=1) = max(pad, ndigits0z(x)) | ||
ndigits(x::Integer) = x == 0 ? 1 : ndigits0z(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iszero(x)
would be more efficient for BigInt, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thank you.
65002d7
to
27def14
Compare
I will merge in a couple of days if no objections. |
27def14
to
af3a36c
Compare
af3a36c
to
7754685
Compare
I made
ndigits(x, b)
with-1 <= b <= 1
an error in all cases, even ifx == 0
, as I thought it was more consistent. There were a lot of dispatch methodsndigits[0z][nb](x, [b])
, so it's possible I messed up one of the paths.Also I removed the
ndigits(::BigInt, [b])
method, to handle the base check in only one place, the drawback being that we then comparex == 0
instead of the probably more efficientx.size == 0
.Hopefully this is overall a simplification of the
ndigits
logic.