Skip to content

Integer#** in C#; Range#include? of one-character String ranges in C# - #118

Merged
Largo merged 2 commits into
masterfrom
claude/vigilant-pascal-nxqqbd
Nov 6, 2026
Merged

Largo merged 2 commits into
masterfrom
claude/vigilant-pascal-nxqqbd

Conversation

@Largo

@Largo Largo commented Nov 6, 2026

Copy link
Copy Markdown
Owner

This PR covers two more #89 items after #117. Figures are Release builds on Linux, net8.0, compared against CRuby 4.0.

1. Integer#** (cf1e069)

rational.rb's def ** sat in front of every Integer power. The C# Integer#** (ClrInteger.Power, ClrBigInteger.Power) is the method again. It hands rational.rb's __ir_pow_slow__ (now private) only three cases:

  • a negative exponent, which gives a Rational;
  • a negative base to a fractional power, which gives a Complex;
  • an exponent that has to be coerced.

Without the prelude, the CLR answers stand, as before. 0 ** NaN is now 0.0, as in MRI, where Math.Pow gives NaN.

master this PR CRuby
3 ** 5 139 ns JIT intrinsic (~0) 13 ns
3 ** 40 367 ns 189 ns 173 ns
3 ** 0.5 287 ns 33 ns 21 ns
3 ** -2 867 ns 793 ns 50 ns

3 ** -2 is still slow: nearly all of it is building the Rational in rational.rb.

2. ('a'..'z').include?("m") (5b879eb)

When both endpoints are one-character ASCII Strings, include? is a byte comparison. The prelude's __string_include__ already took that shortcut, but only after ~1 µs of other calls to get there. RangeOps.Include now answers it directly: 1068 → 182 ns (CRuby ~185).

Testing

  • IronRuby.Tests passes with no failures. The new test Integer_Power1 takes its expected output from CRuby. It covers Rational and Complex results, coercion, 0 ** NaN, Bignum exponents and pow. Range_MinMaxInclude1 gains the one-character cases.
  • ruby/spec with no failures: core/complex, core/float, core/numeric, core/kernel, language, core/range, core/string/upto_spec.rb, library/bigdecimal, library/matrix, library/prime.
  • ruby/spec with known errors: core/integer (15) and core/rational (4) have the same counts as master. They come from mspec's fixnum_max()/fixnum_min() helper.

Still open from #89

  • Rational and Complex arithmetic. Complex(1, 2) takes ~2 µs and c * c ~4 µs, because every object goes through rational.rb and complex.rb.
  • Range#% and #step without a block still take ~2 µs. Most of that is building the Enumerator.

Generated by Claude Code

('a'..'z').include?("m") took ~1 us: the prelude's __string_include__
already compares the bytes for one-character ASCII endpoints, but only
after #__linear__/#__integerish__ and a few more calls. RangeOps answers
it directly now: 1068 -> 182 ns (CRuby ~185).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPwZf7MsYwQdhLBCZCkH2C
… or Complex (#89)

rational.rb's `def **` sat in front of every Integer power, so 3 ** 5 cost
~140 ns and 3 ** 0.5 ~290 (CRuby ~13 and ~21). The C# Integer#**
(ClrInteger.Power, ClrBigInteger.Power) is the method again and hands
rational.rb's __ir_pow_slow__ only a negative exponent (a Rational), a
negative base to a fractional power (a Complex) and what has to be coerced;
0 ** NaN is 0.0 there, as in MRI. Without the prelude the CLR answers stand.

  3 ** 5     139 -> JIT intrinsic
  3 ** 40    367 -> 189 ns   (CRuby 173)
  3 ** 0.5   287 ->  33 ns   (CRuby  21)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPwZf7MsYwQdhLBCZCkH2C
@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 5 included reviews currently available. Your 24 included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 47b1eeb0-9678-4a2e-a920-15c251b004c6
Commits

Reviewing files that changed from the base of the PR and between 0153372 and cf1e069.

Files ignored due to path filters: 1

  • Src/Libraries/Initializers.Generated.cs is excluded by !**/*.generated.*
Files selected for processing: 7

  • Src/IronRuby.Tests/RubyTests.cs
  • Src/IronRuby.Tests/Runtime/MiscTests.cs
  • Src/Libraries/Builtins/Integer.cs
  • Src/Libraries/Builtins/RangeOps.cs
  • Src/Libraries/Extensions/ClrBigInteger.cs
  • Src/Libraries/Extensions/ClrInteger.cs
  • Src/StdLib/ironruby/ironruby/rational.rb
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@Largo
Largo merged commit 7ea839a into master Nov 6, 2026
8 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.

2 participants