Error in Division of BigDecimal #644

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

Projects

None yet

4 participants

@vfrride
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
ginkel commented Apr 17, 2013

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

@vfrride
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
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
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

Here is the work around I am using:

class BigDecimal
  alias :/ :fdiv
end
@BanzaiMan BanzaiMan closed this in #797 Jun 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment