-
-
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
fix digits(n::Unsigned) with neg base for n > typemax(n)÷2
#29187
Conversation
base/intfuncs.jl
Outdated
@@ -743,12 +743,25 @@ julia> digits!([2,2,2,2,2,2], 10, base = 2) | |||
0 | |||
``` | |||
""" | |||
function digits!(a::AbstractVector{T}, n::Integer; base::Integer = 10) where T<:Integer | |||
base < 0 && isa(n, Unsigned) && return digits!(a, convert(Signed, n), base = base) | |||
function digits!(a::AbstractVector{T}, n::Integer; base::Integer = 10, skipfirst=false) where T<: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.
Should we call this __skipfirst__
or something to make it 100% clear that it's not part of the public API?
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.
I had only thought about _skipfirst
! and then didn't bother to re-push, as it's not in the docstring and it's not possible to use this keyword by accident (like it would be with a positional with default). But I realize now that i appears in the output of methods(digits!)
... I guess I should rename.
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.
Gripe: if we had an in-place circshift!(a, 1)
, this keyword wouldn't be needed.
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.
_skipfirst
would be fine too. Depends on how many underscores you need to feel safe.
I've got a slightly different approach that avoids the |
Alternative based on #29187
Alternative based on #29187
Alternative based on #29187
Is it for not polluting the method signature? I was seeing that as a very minor inconvenience only. |
Also, in this version, I called |
Alternative based on #29187 Tests from rforquet's PR linked above.
I started modifying this version slightly but it ended up being quite different. I find the non-recursive version that doesn't introduce any new arguments to |
Given that writing |
The compiler may be able to figure out that it should hoist the |
Yes no problem, I agree that the use of keyword in the last version was not the most beautiful expression of recursivity. I just updated this PR without keyword, but no problem to have this closed in favor of yours. |
Alternative based on #29187 Tests from rforquet's PR linked above.
Merged #29205 instead. |
Alternative based on #29187 Tests from rforquet's PR linked above.
Fixes #29183. The same idea as in #29148 is used.