Skip coerce spec for BigDecimal#div#1273
Conversation
In bigdecimal < 3.2.0, `bigdecimal.div(x, 0)` called `x.coerce` but `bigdecimal.div(x, nonzero)` doesn't call `coerce`. `bigdecimal.div(x,0)` was implemented by `bigdecimal/x`, and calling coerce was just a side effect. It's not a spec.
282e024 to
28679fe
Compare
|
Why do you think that case is a bug? The docs of
So if that holds then |
|
IOW: BigDecimal(1).div(2, 0)
=> 0.5e0So if irb(main):002> obj = Object.new
=> #<Object:0x00007f8b1aa9d218>
irb(main):003> def obj.coerce(other) = [other, 2]
=> :coerce
irb(main):004> BigDecimal(1).div(obj, 0)
=> 0.5e0In light of that I think we should revert this change, but maybe I'm missing some context? Are you changing something related in BigDecimal? Is it specifically about a Rational in Re Rational I see in Ruby 3.3.5 / bigdecimal 3.1.5: irb(main):005> BigDecimal(1).div(2r, 0)
=> 0.5e0
irb(main):006> def obj.coerce(other) = [other, 2r]
=> :coerce
irb(main):007> BigDecimal(1).div(obj, 0)
=> 0.5e0That seems fully expected to me. |
|
I expect Considering I think document of digits==0 is just an implementation detail. I guess what it wanted to say is: Of cource For future improvement, we can change |
In bigdecimal < 3.2.0,
bigdecimal.div(x, 0)calledx.coercebutbigdecimal.div(x, nonzero)doesn't callcoerce.bigdecimal.div(x,0)was implemented bybigdecimal/x, and calling coerce was just a side effect.It's not a specification.