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 losses precision in JRuby 1.7.19 #2650

Closed
eljojo opened this issue Mar 5, 2015 · 3 comments
Closed

BigDecimal losses precision in JRuby 1.7.19 #2650

eljojo opened this issue Mar 5, 2015 · 3 comments

Comments

@eljojo
Copy link

eljojo commented Mar 5, 2015

Hi,
I noticed there's a loss in precision when using 1.7.19. This is fixed in 9000.
I thought it'd be a good idea to report this anyways.

1.7.19:

$ ruby -v
jruby 1.7.19 (2.0.0p598) 2015-01-29 20786bd on Java HotSpot(TM) 64-Bit Server VM 1.8.0_25-b17 +jit [darwin-x86_64]
$ irb
>> require 'bigdecimal'
=> true
>> BigDecimal.new("10.9", 2).to_f
=> 11.0

9.0.0.0.pre1:

$ ruby -v
jruby 9.0.0.0.pre1 (2.2.0p0) 2015-01-20 d537cab Java HotSpot(TM) 64-Bit Server VM 25.25-b02 on 1.8.0_25-b17 +jit [darwin-x86_64]
$ irb
>> require 'bigdecimal'
=> true
>> BigDecimal.new("10.9", 2).to_f
=> 10.9

MRI 2.2.0:

$ ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
$ irb
>> require 'bigdecimal'
=> true
>> BigDecimal.new("10.9", 2).to_f
=> 10.9

I'm running this on mac using OS X 10.10.2 and the JVM:

$ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
@headius
Copy link
Member

headius commented Mar 12, 2015

Hmm...could be a difference in default rounding mode?

@headius
Copy link
Member

headius commented Mar 12, 2015

Good beginner bug to sort out exactly why we differ here.

@eljojo
Copy link
Author

eljojo commented Mar 12, 2015

I just tested and under 1.7.19, BigDecimal.new("10.4", 2).to_f => 10.0

@mkristian mkristian self-assigned this Mar 16, 2015
mkristian added a commit that referenced this issue Mar 20, 2015
follow what MRI is doing and ignore the precision

fixes #2650

Sponsored by Lookout Inc.
@enebo enebo added this to the JRuby 1.7.20 milestone Apr 28, 2015
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

5 participants