ndigits: make base and pad keywords #27908
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My initial motivation was that
ndigits(x, [base])
andlog([base], x)
do quite related things (ndigits(x, base)
andlog(base, x)
are numerically close), but they take their arguments in reverse order, which is rather confusing. One fix would be to reverse the arguments ofndigits
, but asndigits
is also closely related todigits
, it seems nicer to use keywords, to follow thedigits
API. Also, this allows to specifypad
while using the default value forbase
-- which also removes one TODO from the code :)I had started to do the same for
Base.ndigits0z
, but I noticed some performance degradation, so I suspect that constant propagation does not happen with keyword argument... Asndigits0z
may be used in somewhat more performance sensitive code and is not exported, I propose to keep its old API for now (and usingpad=0
inndigits
has the same behavior asndigits0z
, sondigits
is enough for user-facing API).