-
Notifications
You must be signed in to change notification settings - Fork 185
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
Round behaves differently than MRI/JRuby #3676
Comments
#3360 might be related |
Thank you for the report, we'll look into it. |
Something interesting about these 2 float values is they seem to be exact:
So at first sight this does look like a bug in rounding. |
I understand and that's why I only used "behave differently" in the title. What's interesting to me is that JRuby also runs on JVM, but it managed to behave the same way as MRI. Also, the reason for rounding in the first place is an attempt to reduce the impact of float precision error in sass-embedded gem. In Sass language, we define "fuzzy equality" as:
This "fuzzy equality" is necessary because we have Sass implementation across Dart, JS, Ruby, C++, Java and many other languages, and different language implementations often lead to different float precision for math operations. Specifically, Sass recently added support for CSS Color Level 4 which introduced the conversion of colors between color spaces. This involves lots of mathematic operation. What happened is that TruffleRuby generally had higher precision errors than MRI/JRuby, comparing to the Dart reference implementation. This rounding behavior difference is just the most obvious case that would occasionally fail the fuzzy equality test immediately. |
This can be worked around as:
|
I checked and found JRuby indeed ported the round implementation from CRuby, which explains why they behave the same way: https://github.com/ruby/ruby/blob/v3_3_5/numeric.c#L2449-L2578 |
Right, I think we should do the same, I'm not sure why we had our own variant here. |
MRI
TruffleRuby
The text was updated successfully, but these errors were encountered: