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

Bad to_s output for extremely small floats #4245

Closed
headius opened this issue Oct 24, 2016 · 2 comments
Closed

Bad to_s output for extremely small floats #4245

headius opened this issue Oct 24, 2016 · 2 comments

Comments

@headius
Copy link
Member

headius commented Oct 24, 2016

This is on JRuby master (pre-9.1.6.0).

[] ~/projects/rails/activesupport $ jruby -e "p 1.0e-100"
0.0

[] ~/projects/rails/activesupport $ ruby23 -e "p 1.0e-100"
1.0e-100

I confirmed the proper value does make it into the Float object, but when we to_s we're losing information.

This is used by Rails in their NumberToRoundedConverter: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb#L63

As a result of us to_s'ing this value, we end up with a 0.0 multiplier. This breaks tests in Rails activesupport/test/number_helper_test.rb here: https://github.com/rails/rails/blob/master/activesupport/test/number_helper_test.rb#L195

@etehtsea
Copy link
Contributor

I'm also seeing test_sprintf_float failure on macOS and Ubuntu Xenial:

Failure: test_sprintf_float(TestKernel)
/home/ubuntu/jruby/test/jruby/test_kernel.rb:405:in `test_sprintf_float'
     402:   # JRUBY-4802
     403:   def test_sprintf_float
     404:     assert_equal "0.00000", Kernel.sprintf("%.5f", 0.000004)
  => 405:     assert_equal "0.00001", Kernel.sprintf("%.5f", 0.000005)
     406:     assert_equal "0.00001", Kernel.sprintf("%.5f", 0.000006)
     407:   end
     408:
<"0.00001"> expected but was
<"0.00000">

@kares
Copy link
Member

kares commented Jun 20, 2018

this is now working on 9.2 as well as 9.1.16.0 :

jruby-9.1.16.0 :010 > p 1.0e-100
1.0e-100
 => 1.0e-100

@kares kares closed this as completed Jun 20, 2018
@kares kares added this to the JRuby 9.1.16.0 milestone Jun 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants