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

High precision BigDecimal to Rational conversion wildly inaccurate #4711

joshwlewis opened this Issue Jul 10, 2017 · 1 comment


None yet
3 participants

joshwlewis commented Jul 10, 2017


  • Darwin 16.6.0 (MacOS Sierra 10.12.5)
  • jruby (2.3.1) 2017-03-06 90fc7ab Java HotSpot(TM) 64-Bit Server VM 25.131-b11 on 1.8.0_131-b11 +jit [darwin-x86_64]

Expected Behavior

In each MRI version I've tried, I am able to convert a high-precision BigDecimal to a reasonably similar Rational value. For instance, in MRI 2.4.1:

require 'bigdecimal'
# => true"3.141592653589793238462643383279502884197169").to_r
# => (3141592653589793238462643383279502884197169/1000000000000000000000000000000000000000000)

# => 3.141592653589793

Actual Behavior

require 'bigdecimal'
# => true"3.141592653589793238462643383279502884197169").to_r
# => (448798950512827605494663340468500412028167/1317624576693539401)

# => 3.4061215800865547e+23

I'd expect something in the region of 3.14 here, but instead, the result is approximately 340 sextillion.

Other info

  • This behavior exists on my CI server running Ubuntu and the same JRuby version
  • This behavior exists with Rational(high_precision_pi), too
  • This behavior can be prevented with an intermediate string conversion like high_precision_pi.to_s.to_r.
  • Could be related to #4200?

@kares kares added this to the JRuby milestone Jul 10, 2017

@kares kares added the core label Jul 10, 2017

@kares kares self-assigned this Jul 11, 2017

kares added a commit to kares/jruby that referenced this issue Jul 11, 2017

kares added a commit to kares/jruby that referenced this issue Jul 11, 2017


This comment has been minimized.


headius commented Jul 11, 2017

Yeah, this is pretty wacky. Looks like @kares is looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment