Repository navigation
Integer divmod/remainder/gcd/lcm/gcdlcm accept Bignum and Float operands - #466
Merged
Merged
Conversation
The Integer division family coerced both operands through int64, so a Bignum
receiver or argument raised a spurious RangeError ("bignum too big to convert
into 'long'") or a TypeError, and a Float argument to divmod/remainder was
rejected outright.
They now compute in math/big when either side is a Bignum:
- divmod / gcdlcm are floored, matching MRI's sign-of-divisor modulo.
- remainder truncates toward zero.
- gcd / lcm / gcdlcm accept any Integer/Bignum, raise "not an integer" for a
Float or non-integer, and treat gcd(0,0) as 0.
- divmod / remainder accept a Float argument (Integer quotient, Float modulo),
run the coerce protocol for a non-numeric argument that offers #coerce, and
otherwise raise the canonical "X can't be coerced into Integer"; division by
zero still raises ZeroDivisionError, including for a Bignum receiver.
The now-unused int64 helpers (gcdInt / absInt / bigArg) are removed.
Verified against ruby 4.0.6. Whole-package coverage stays at 100%; the ruby/spec
floor rises 15750 -> 15770 (language+core now 15834 passing, +19).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Integer division family coerced both operands through
int64, so a Bignumreceiver or argument raised a spurious
RangeError(bignum too big to convert into 'long') or aTypeError, and a Float argument todivmod/remainderwasrejected outright (
core/integerdivmod/remainder/gcd/lcm/gcdlcm errored onthese).
They now compute in
math/bigwhen either side is a Bignum:divmod/gcdlcmare floored, matching MRI's sign-of-divisor modulo.remaindertruncates toward zero.gcd/lcm/gcdlcmaccept any Integer/Bignum, raisenot an integerfora Float or non-integer, and treat
gcd(0, 0)as0.divmod/remainderaccept a Float argument (Integer quotient, Floatmodulo), run the coerce protocol for a non-numeric argument that offers
#coerce, and otherwise raise the canonicalX can't be coerced into Integer;division by zero still raises
ZeroDivisionError, including for a Bignumreceiver.
The now-unused
int64helpers (gcdInt/absInt/bigArg) are removed.Verified against ruby 4.0.6. Whole-package coverage stays at 100%; the ruby/spec
ratchet floor rises 15750 → 15770 (language+core now 15834 passing, +19, zero
regressions in a deterministic per-file sweep).
🤖 Generated with Claude Code