-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
following MRI's 'weird' to_int conversion #4984
Comments
I'm not sure which bit you think is weird, so apologies if I am explaining something to you that you already understand. A 64-bit floating point number cannot represent the number
When you call This is explained in this Ruby FAQ. https://github.com/rdp/ruby_tutorials_core/wiki/ruby-talk-faq#floats_imprecise And this other document as well. https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html With that information in mind, I think the behaviour of What do you think it should do instead? |
This issue just brought back the nightmares of my numerical analysis (singular) class at college. This is known and expected as well. Also notice that nearly all other languages which support this float->int have the same behavior:
Base 2 representation of floats just don't quite line up with our base 10 expectations... |
Thanks Chris and Tom, guess its back-2-school for me than :) For the record, as I was stuck elsewhere - did not pay much attention, when I run into this and somehow wrongly assumed As Chris confirmed (on IRC) detecting a float precision being lost isn't possible in general ... Somehow expected a narrow case - that Ruby might handle a number growing too big (as with integers). |
its obviously there for compatibility, but does it make sense?
maybe JRuby doesn't need to follow blindly as this could be considered an MRI bug:
The text was updated successfully, but these errors were encountered: