Skip to content

Add Numeric/Integer/Float #numerator and #denominator - #449

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster21
Aug 25, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster21

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

#numerator and #denominator were undefined on Integer and Float
(NoMethodError). They are now defined in the prelude:

  • Numeric#numerator / #denominator delegate to those of #to_r, covering any
    Numeric subclass that defines #to_r;
  • Integer overrides them to return self and 1 directly (Bignum included);
  • Float uses the numerator/denominator of its exact rational value when finite,
    and — since Infinity and NaN have no rational form — returns the Float itself
    as the numerator and 1 as the denominator, matching MRI.

Verified against ruby 4.0.6. Full package coverage stays at 100.0% (the
frozen prelude was regenerated). Zero-regression rubyspec sweep;
core/float/numerator 0 → 5, core/float/denominator 0 → 3,
core/integer/{numerator,denominator} 0 → 1 each,
core/numeric/{numerator,denominator} 0 → 1 each (the one remaining error in
each numeric spec is a spec_helper mock_numeric limitation — the shim makes a
plain mock rather than a Numeric subclass — not the method).

🤖 Generated with Claude Code

#numerator and #denominator were undefined on Integer and Float (NoMethodError).
They are now defined in the prelude:

  - Numeric#numerator / #denominator delegate to those of #to_r, covering any
    Numeric subclass that defines #to_r;
  - Integer overrides them to return self and 1 directly (Bignum included);
  - Float uses the numerator/denominator of its exact rational value when finite,
    and — since Infinity and NaN have no rational form — returns the Float itself
    as the numerator and 1 as the denominator, matching MRI.

Verified against ruby 4.0.6. Full package coverage stays at 100.0% (the frozen
prelude was regenerated). Zero-regression rubyspec sweep; core/float/numerator
0 -> 5, core/float/denominator 0 -> 3, core/integer/{numerator,denominator}
0 -> 1 each, core/numeric/{numerator,denominator} 0 -> 1 each (the one remaining
error in each numeric spec is a spec_helper mock_numeric limitation — the shim
makes a plain mock rather than a Numeric subclass — not the method).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 8ec1787 into main Aug 25, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster21 branch August 25, 2026 10:23
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