Skip to content

Convert BigDecimal.mode, BigDecimal.limit and the digits of add, sub and to_s with to_int like CRuby - #10201

Merged
headius merged 1 commit into
jruby:jruby-10.0from
taxor03:fix-bigdecimal-to-int-10.0
Dec 3, 2026
Merged

headius merged 1 commit into
jruby:jruby-10.0from
taxor03:fix-bigdecimal-to-int-10.0

Conversation

@taxor03

@taxor03 taxor03 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #10196.

BigDecimal.mode, BigDecimal.limit, the precision of BigDecimal#add and #sub, and the digits of BigDecimal#to_s used castAsFixnum or toString() on their argument, so an object that converts with to_int was rejected or ignored. They now convert with toInt like CRuby's bigdecimal (NUM2INT in BigDecimal_mode, BigDecimal_limit and BigDecimal_to_s, NUM2LONG in check_int_precision). A String argument to to_s is still a format string, and to_s(0) and to_s(-1) now raise ArgumentError ("argument must be positive") as in CRuby instead of ignoring the argument.

This adds examples to the library/bigdecimal specs of mode, limit, add, sub and to_s. They fail before this change and pass after it, and pass on CRuby 3.4.13 and 4.0.10. The whole spec/ruby/library/bigdecimal directory shows no new failures.

This targets jruby-10.0. It also applies cleanly to master, where the new examples pass with the default parser and with -Xparser.prism.

@headius headius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More good cleanup of coercion logic.

@headius headius added this to the JRuby 10.0.9.0 milestone Dec 3, 2026
@headius
headius merged commit 5978453 into jruby:jruby-10.0 Dec 3, 2026
127 checks passed
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.mode, BigDecimal.limit and the digits of add, sub and to_s do not convert with to_int BigDecimal.mode, BigDecimal.limit and the digits of add, sub and to_s do not convert with to_int

2 participants