-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Problem with padding in digits function #22837
Comments
Funny, I was exactly working on fixing this one now ;-) |
Maybe this has been addressed elsewhere but why should they return 0 element vectors and not 1 element vectors? "0" is the base T representation of "0" in any base (poorly worded but you get the idea) and that has length 1. |
Then you are free to use |
Yes, it's nice if 'digits(k, b, p)' gives a vector of length p for all '0<=k<=b^p-1' Thank you for looking into this @rfourquet |
I don't mean to be pedantic but does padding not imply superfluous zeros? See python's zfill or string formatting for an example.
It seems like having it return an empty array would break some cases where one would want to construct this array and then call some element from it. This seems like confusing behavior since all other cases will return a strictly non-empty array. |
If it breaks some cases, then those case were relying on a bug; this is unfortunate but I don't think it's worth it now to go through deprecation just for fixing a bug. The default, when |
(My first comment attempt isn't showing up so maybe this will be a near duplicate). Mathematically, "emptiness/nothing" is not the same as "zero", so I really still think that all integers should return some non-empty array (but I guess I don't really have much say haha). NaN would be the only case that I think an empty array should be returned but it is a float. About the cases of relying on a bug, from reading the documentation
I would have expected the behavior to always return something that is non-empty so it would seem like relying on it being empty would be relying on a bug since that is sort of confusing behavior (as 0 is a number and has one digit). |
A last attempt: with |
Base.ndigits0z(0, b) must return 0 (fix #22837)
Zero is a zero-digit number in any base. Why? How many powers of the base do you add together to get zero? None of them – i.e. zero digits. The fact that we represent zero as a string with a single |
In Julia 0.6 I get:
I think both should return a vector of length 0. This is the behavior in Julia 0.5 for all bases and in Julia 0.6 for the special cases where the base is 2, 8, 10, and 16. The source code for the digits function did not change between Julia 0.5 and 0.6, but the code for the ndigits0z function did change.
The text was updated successfully, but these errors were encountered: