-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix float number overflow in range rand method #13825
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
base: master
Are you sure you want to change the base?
Conversation
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.
Float64::MIN..Float32::MAX
still overflows, in case you want to fix that as well
Instead of returning
We could indeed handle overflow issues with inconsistent start and end types of ranges with more code, but I don't think it's worth it, and throwing an exception tells the caller to remind the caller to improve the code is simpler and clearer. The optimizations I made are just the usual practice in the field of numerical calculations. |
Replacing expressions like |
If want to consider the return value type, expect inconsistencies if big numbers are involved:
I was wondering if it should be like |
I found that the current implementation does not support big numbers. |
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.
I figure that changing the algorithm for rand(Range)
should take #12546 into account. Are you aware of that issue?
This implementation seems to exhibit the same correctness problem.
Closes: #7883