Skip to content

Fix BigDecimal#+, #-, #add, #sub failing when coercing doesn't return a BigDecimal#9204

Merged
headius merged 2 commits intojruby:masterfrom
trinistr:fix-bigdecimal-add-sub-coercion
Jan 30, 2026
Merged

Fix BigDecimal#+, #-, #add, #sub failing when coercing doesn't return a BigDecimal#9204
headius merged 2 commits intojruby:masterfrom
trinistr:fix-bigdecimal-add-sub-coercion

Conversation

@trinistr
Copy link
Contributor

@trinistr trinistr commented Jan 30, 2026

Fixes #9194

For some reason, only in cases of addition and subtraction precision gets assigned to result. Probably, this is why only in these two methods there was a cast. Now, there is a test for type of result in both cases. Also for null, as subtraction didn't check for that. Addition and subtraction with tricky types works now:

irb(main):002> BigDecimal(10) + Complex(1,2)
=> (0.11e2+2i)
irb(main):003> BigDecimal(10) - Complex(1,2)
=> (0.9e1-2i)

mult() has this:

        if (val == null) { // TODO: what about n arg?
            return callCoerced(context, sites(context).op_times, b, true);
        }

So it seems that precision may be lost or ignored in most operations. This PR does not address any of that.

@trinistr trinistr marked this pull request as ready for review January 30, 2026 10:11
instanceof will not return true for null.
@headius headius merged commit caac478 into jruby:master Jan 30, 2026
76 of 77 checks passed
@headius headius added this to the JRuby 10.0.3.0 milestone Jan 30, 2026
@trinistr trinistr deleted the fix-bigdecimal-add-sub-coercion branch January 30, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigDecimal#+, #-, #add, #sub always try to cast result of coercion to RubyBigDecimal

2 participants