-
Notifications
You must be signed in to change notification settings - Fork 432
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
When using gen_range
the panics appear to not be documented correctly resulting in potential overflow
#1337
Comments
This statement does not apply equally to integer and floating-point types. See #1090. Also, I'm not sure if this applies equally to 0.8.5 (which is quite old) and the latest in |
Hi thanks for the reply. i read the other issue and it does seem nearly identical to this issue -- but im unsure if there was a positive conclusion to it?
Im not sure to which statement you are referring to; Or is it the absence of a statement regarding bounds checking? That said it would not only be the case of min & max in this event but max and any negative value or min and any positive number would cause overflow in this case. Would not a # Panic descrbing the limitations on overflow be called for in this event? e.g
While ensuring that those bounds are respected by the compiler is probably tricky documenting the caveat seems appropriate unless of course im missing something obvious about the documentation where this limitation is spelled out. It wasn't obvious to three of our engineers which made me believe the docs could benefit from being more explicit -- again unless its documented elsewhere |
Yes, we probably do need better docs regarding this. Regarding panic on overflow, we should consider this. |
I just checked that this panics on master, but the docs of |
Fixed in #1351. |
Thanks @vks |
Hello,
I recently tried to run this code in one of our tests
The result was an overflow error which makes sense in context of this ( https://docs.rs/rand/latest/src/rand/distributions/uniform.rs.html#884 )
BigNumber - ( - BigNumber ) == VeryBigNumber
So overflow here is not surprising but in the list of panics here -> https://docs.rs/rand/latest/rand/trait.Rng.html#method.gen_range
We see only considerations for "if the range is empty" leading me to initially believe using min and max ranges for a type as valid but I believe they are not?
The text was updated successfully, but these errors were encountered: