-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 Int#downto with unsigned int going down to 0. #6678
Conversation
src/int.cr
Outdated
x -= 1 | ||
end | ||
end |
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.
Wrong indent.
What happens with |
Hum. |
@gmarcais You can probably do something like (edit: changed from |
I modified to |
Added spec cases for .to_a. |
Please also fix |
6bc2488
to
a888c8d
Compare
I don't get that error. It does not seem to have anything to do with the current patch:
I changed the comment on the patch. Does this have anything to do with it? (Seems unlikely, but I ask nevertheless). Any idea what went wrong? |
That's correct, nothing to worry about. |
@gmarcais Why close? |
I did not do that. Not sure what happened. Can it be reopened (I personally cannot apparently)? I was still considering fixing the step method and related. |
I added a version of the step method that does not overflow as well. |
@gmarcais You probably need to rebase your branch against |
@asterite Yes, I rebased and added the step method. That allowed me to reopen the issue. I am not yet convinced about my implementation because of the following issue. The step function is possibly a mess of many different types: One can imagine crazier combination: Should there be some type restrictions? |
I don't think it would hurt to just restrict the arguments to the same type as |
Yeah, it's a crazy combination. Right now you can even do: 1.step(to: 3.5, by: 0.5) do |i|
puts i # => 1.0, 1.5, ...
end I'm not sure restricting the types is the way to go, but we could try it. But I'd try to not involve |
I'd cast to the But yes, another PR please. |
OK, I reverted the step method changes. The current PR only contains the upto and downto methods. I'll create a new PR for step. |
See issue #6669. When using unsigned integers with the downto method, and the to is equal to 0, the code is an endless loop:
Both version of the downto method (with and without a block) are fixed by this patch.