Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
BigDecimal does not coerce properly during division #2538
BigDecimal raises an error when trying to divide by a non-numeric value, even if it defines #coerce. This is inconsistent with other numeric types and with the other operators in BigDecimal, which properly coerce the value.
Trivial example that reproduces the problem:
class MyNum def *(other) 33 end def /(other) 99 end def coerce(other) [MyNum.new, self] end end
Confirmed on both 1.7 branch and master. 1.9+ from a compay standpoint. Added missing code from original report so it is easier to reproduce below:
require 'bigdecimal' require 'bigdecimal/util' class MyNum def *(other) 33 end def /(other) 99 end def coerce(other) [MyNum.new, self] end end p 10.to_d * MyNum.new p 10.0 / MyNum.new p 10.0.to_d / MyNum.new