Skip to content

Integer divmod/remainder/gcd/lcm/gcdlcm accept Bignum and Float operands - #466

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster36
Aug 26, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster36

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

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 (core/integer divmod/remainder/gcd/lcm/gcdlcm errored on
these).

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
ratchet floor rises 15750 → 15770 (language+core now 15834 passing, +19, zero
regressions in a deterministic per-file sweep).

🤖 Generated with Claude Code

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>
@tannevaled
tannevaled merged commit fd48f2c into main Aug 26, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster36 branch August 26, 2026 21:41
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.

1 participant