Skip to content
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 overflow in #5550 #5555

Closed
wants to merge 1 commit into from
Closed

Fix overflow in #5550 #5555

wants to merge 1 commit into from

Conversation

mschauer
Copy link
Contributor

and test for #5550.

Ping @lindahua

@JeffBezanson
Copy link
Member

related: #2537

@lindahua
Copy link
Contributor

On 64-bit machine:

julia> typemin(Int64):typemax(Int64)
ERROR: OverflowError()

julia> typemin(Int32):typemax(Int32)
-2147483648:2147483647

Would typemin(Int32):typemax(Int32) issue OverflowError on 32-bit machine?

@mschauer
Copy link
Contributor Author

Yes. Already 0:typemax(Int) overflows on any machine, as range lengths are (signed) Ints, and counting starts at an empty range with r.len = 0. 0:typemax(Int)-1 is the max.

@lindahua
Copy link
Contributor

Note that one can call rand(Int32) to generate a random integer on whole range.

@mschauer
Copy link
Contributor Author

If you know in advance that the range is in fact typemin(Int32):typemax(Int32), then yes.

Similar problem also with StatsBase.randi by the way,
StatsBase.randi(typemin(Int), typemax(Int)) overflows on any system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants