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

Error in Division of BigDecimal #644

Closed
vfrride opened this Issue Apr 16, 2013 · 5 comments

Comments

Projects
None yet
4 participants
@vfrride
Copy link

vfrride commented Apr 16, 2013

jRuby 1.7.3 is giving an incorrect (or at least inconsistent with MRI and jRuby 1.6.5) answer for a simple division problem

irb(main):002:0> require 'bigdecimal'
=> true
irb(main):003:0> BigDecimal.new(11023)/2.2046
=> #<BigDecimal:6515d4f9,'0.55115E4',5(8)>

The correct answer is 5000. MRI and jRuby 1.6.5 give the correct answer. 1.7.3 does not

@ginkel

This comment has been minimized.

Copy link

ginkel commented Apr 17, 2013

Seems to be a duplicate of https://jira.codehaus.org/browse/JRUBY-7101

@vfrride

This comment has been minimized.

Copy link
Author

vfrride commented Apr 17, 2013

Although I suspect that the root of the problem is the same as the problem in JIRA this issue report does add some information. It is not just numbers between 0 and 1 as my case divides by 2.2046. I also tried 2.7046:

BigDecimal.new(11023)/2.7046
=> #<BigDecimal:3559b630,'0.55115E4',5(8)>

So it looks the mantissa is being dropped from the divisor?

@ginkel

This comment has been minimized.

Copy link

ginkel commented Apr 17, 2013

@vfrride Exactly. That's what causes a division by zero in the JIRA issue, but the issue is much more general, as you pointed out: When dividing a BigDecimal by a float, the divisor seems to be cast into a Fixnum.

@vfrride

This comment has been minimized.

Copy link
Author

vfrride commented Apr 17, 2013

@ginkel It's hard to tell from the JIRA if any work is being done on this. I'd be happy to at least create a test on the ruby side, and possibly try to figure out a fix, but I don't want to duplicate effort. Do you know if anyone is working on it?

@michaelgpearce

This comment has been minimized.

Copy link

michaelgpearce commented Apr 19, 2013

Here is the work around I am using:

class BigDecimal
  alias :/ :fdiv
end
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.