Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
High precision BigDecimal to Rational conversion wildly inaccurate #4711
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 BigDecimal.new("3.141592653589793238462643383279502884197169").to_r # => (3141592653589793238462643383279502884197169/1000000000000000000000000000000000000000000) _.to_f # => 3.141592653589793
require 'bigdecimal' # => true BigDecimal.new("3.141592653589793238462643383279502884197169").to_r # => (448798950512827605494663340468500412028167/1317624576693539401) _.to_f # => 3.4061215800865547e+23
I'd expect something in the region of 3.14 here, but instead, the result is approximately 340 sextillion.