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 and Rational multiplication rounds the rational number #1695

Closed
danshep opened this Issue May 14, 2014 · 6 comments

Comments

Projects
None yet
5 participants
@danshep
Copy link

danshep commented May 14, 2014

BigDecimal.new('100') * Rational(1, 100)

currently returns 0. It should be returning 1.

irb(main):001:0> require 'rational'
=> true
irb(main):002:0> require 'bigdecimal'
=> true
irb(main):003:0> BigDecimal.new('100') * Rational(1, 100)
=> #<BigDecimal:504f4029,'0.0',1(4)>
irb(main):004:0> JRUBY_VERSION
=> "1.7.12"
irb(main):005:0> RUBY_VERSION
=> "1.9.3"

>jruby -v
jruby 1.7.12 (1.9.3p392) 2014-04-15 643e292 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_51-b13 [Windows 7-amd64]

It appears to be rounding the rational number before multiplying:

irb(main):011:0> BigDecimal.new('100') * Rational(50, 100)
=> #<BigDecimal:144cf50,'0.1E3',1(4)>
irb(main):012:0> BigDecimal.new('100') * Rational(49, 100)
=> #<BigDecimal:1fec595,'0.0',1(4)>

The same operation works correctly in cruby:

d:\development\rubydev\tickets>irb
irb(main):001:0> require 'rational'
=> true
irb(main):002:0> require 'bigdecimal'
=> true
irb(main):003:0> BigDecimal.new('100') * Rational(1, 100)
=> #<BigDecimal:2a2aae0,'0.1E1',9(36)>
irb(main):004:0> RUBY_VERSION
=> "1.9.3"
irb(main):005:0> exit

ruby -v
ruby 1.9.3p484 (2013-11-22) [i386-mingw32]

enebo added a commit that referenced this issue Jun 14, 2014

@enebo enebo added this to the JRuby 1.7.13 milestone Jun 14, 2014

@enebo enebo closed this Jun 14, 2014

@enebo

This comment has been minimized.

Copy link
Member

enebo commented Jun 19, 2014

Reverted in ec1a2ca. This broke other bigdecimal tests and I am going back to last state until we figure out how to do this right (regressions in ant test-extended).

@enebo enebo reopened this Jun 19, 2014

@enebo enebo modified the milestones: JRuby 1.7.14, JRuby 1.7.13 Jun 24, 2014

@k77ch7

This comment has been minimized.

Copy link
Contributor

k77ch7 commented Jun 26, 2014

It works for me in current jruby-1_7 branch.
Could you tell me which bigdecimal tests were broken?

@mkristian

This comment has been minimized.

@k77ch7

This comment has been minimized.

Copy link
Contributor

k77ch7 commented Jun 26, 2014

@mkristian Thanks for your reply. I'll check that out.

mkristian added a commit that referenced this issue Jul 1, 2014

Merge pull request #1766 from k77ch7/GH-1745
Fix for issue #1695 ; DateTime#jd’ should return chronological Julian day number

@enebo enebo modified the milestones: JRuby 1.7.14, JRuby 1.7.15 Aug 27, 2014

@k77ch7

This comment has been minimized.

Copy link
Contributor

k77ch7 commented Sep 29, 2014

I was fixed again. @enebo @mkristian Please review #2011.

@headius

This comment has been minimized.

Copy link
Member

headius commented Nov 2, 2014

Fixed by #2011!

@headius headius closed this Nov 2, 2014

k77ch7 added a commit to k77ch7/jruby that referenced this issue Dec 11, 2014

headius added a commit that referenced this issue Jan 12, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.