-
-
Notifications
You must be signed in to change notification settings - Fork 942
Closed
Description
Environment
- Darwin 16.6.0 (MacOS Sierra 10.12.5)
- jruby 9.1.8.0 (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
BigDecimal.new("3.141592653589793238462643383279502884197169").to_r
# => (3141592653589793238462643383279502884197169/1000000000000000000000000000000000000000000)
_.to_f
# => 3.141592653589793Actual Behavior
require 'bigdecimal'
# => true
BigDecimal.new("3.141592653589793238462643383279502884197169").to_r
# => (448798950512827605494663340468500412028167/1317624576693539401)
_.to_f
# => 3.4061215800865547e+23I'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 BigDecimal multiplication with Rational produces garbage digits within the requested precision. #4200?
Reactions are currently unavailable