Skip to content

BigDecimal does not coerce properly during division #2538

@undefinedvalue

Description

@undefinedvalue

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
> 10.to_d * MyNum.new
33
> 10.0 / MyNum.new
99
> 10.0.to_d / MyNum.new
MyNum can't be coerced into BigDecimal

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions