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

BigDecimal#to_r produces grossly incorrect results #3728

Closed
felixvf opened this issue Mar 13, 2016 · 3 comments
Closed

BigDecimal#to_r produces grossly incorrect results #3728

felixvf opened this issue Mar 13, 2016 · 3 comments

Comments

@felixvf
Copy link

felixvf commented Mar 13, 2016

Environment

# jruby -v
jruby 9.0.5.0 (2.2.3) 2016-01-26 7bee00d OpenJDK 64-Bit Server VM 25.72-b15 on 1.8.0_72-b15 +jit [linux-amd64]

Expected Behavior

# irb
2.3.0 :001 > require 'bigdecimal'
 => true 
2.3.0 :002 > BigDecimal.new("5").to_f
 => 5.0 
2.3.0 :003 > BigDecimal.new("5").to_r.to_f
 => 5.0 
2.3.0 :004 > BigDecimal.new("5").to_r
 => (5/1) 
2.3.0 :005 > BigDecimal.new("1234.56789").to_r
 => (123456789/100000) 

Actual Behavior

# irb
jruby-9.0.5.0 :001 > require 'bigdecimal'
 => true 
jruby-9.0.5.0 :002 > BigDecimal.new("5").to_f
 => 5.0 
jruby-9.0.5.0 :003 > BigDecimal.new("5").to_r.to_f
 => 1.0 
jruby-9.0.5.0 :004 > BigDecimal.new("5").to_r
 => (1/1) 
jruby-9.0.5.0 :005 > BigDecimal.new("1234.56789").to_r
 => (123456789/50) 
@lucasallan
Copy link
Member

I'm not able to reproduce it in master. cc @kares @felixvf

# irb
>>  require 'bigdecimal'
=> true
>>  BigDecimal.new("5").to_f
=> 5.0
>> BigDecimal.new("5").to_r.to_f
=> 5.0
>> BigDecimal.new("5").to_r
=> (5/1)
>>  BigDecimal.new("1234.56789").to_r
=> (123456789/100000)
>> JRUBY_VERSION
=> "9.1.0.0-SNAPSHOT"

@Lan5432
Copy link
Contributor

Lan5432 commented Mar 14, 2016

I also tried reproducing the bug and had the same output as lucasallan, BigDecimal appears to be fine in 9.1

EDIT:

irb(main):001:0> require 'bigdecimal'
=> true
irb(main):002:0> BigDecimal.new("5").to_f
=> 5.0
irb(main):003:0> BigDecimal.new("5").to_r.to_f
=> 5.0
irb(main):004:0> BigDecimal.new("5").to_r
=> (5/1)
irb(main):005:0> BigDecimal.new("1234.56789").to_r
=> (123456789/100000)
irb(main):006:0> 

(Having troubles to show the version)

@kares
Copy link
Member

kares commented Mar 14, 2016

thanks, it seems to be a duplicate of #3616 which has been fixed with 16b13e1

@kares kares closed this as completed Mar 14, 2016
@kares kares added this to the Invalid or Duplicate milestone Mar 14, 2016
ahorek added a commit to ahorek/jruby that referenced this issue May 25, 2016
headius added a commit that referenced this issue Aug 23, 2016
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

4 participants