Skip to content

Implement Integer.sqrt - #420

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster2
Aug 21, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster2

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Integer.sqrt was missing (calling it raised NoMethodError), so
core/integer/sqrt_spec.rb was 0/6.

It returns the floored integer square root ⌊√n⌋ of its argument:

  • the argument is coerced with #to_int (a new integerArg helper, so a
    Float or a user #to_int object works; a non-coercible value, or a
    #to_int returning a non-Integer, raises TypeError);
  • a negative argument raises Math::DomainError
    ("Numerical argument is out of domain - \"isqrt\"");
  • the result is computed with big.Int.Sqrt, so Bignum arguments and
    results work (Integer.sqrt(10**400) == 10**200).

Verified against ruby 4.0.6; sqrt_spec now passes 6/6. New
integerArg at 100% coverage, the whole-suite coverage gate stays at
100.0%, and a full language+core sweep shows no regressions.

🤖 Generated with Claude Code

Integer.sqrt was missing (NoMethodError), so sqrt_spec was 0/6. It
returns the floored integer square root of its argument: the argument is
coerced with #to_int (via a new integerArg helper, so a Float or a
user #to_int object works), a negative value raises Math::DomainError
("Numerical argument is out of domain - \"isqrt\""), and the result is
computed with big.Int.Sqrt so Bignum arguments (and results) work
(Integer.sqrt(10**400) == 10**200).

Verified against ruby 4.0.6; sqrt_spec now 6/6.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 283e225 into main Aug 21, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster2 branch August 21, 2026 08:08
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