Error in Division of BigDecimal #644

vfrride opened this Issue Apr 16, 2013 · 5 comments


None yet

4 participants

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
=> #<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 commented Apr 17, 2013

Seems to be a duplicate of

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:3559b630,'0.55115E4',5(8)>

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

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 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?


Here is the work around I am using:

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