Repository navigation
Implement Integer.sqrt - #420
Merged
Merged
Conversation
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>
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.
Integer.sqrtwas missing (calling it raisedNoMethodError), socore/integer/sqrt_spec.rbwas0/6.It returns the floored integer square root ⌊√n⌋ of its argument:
#to_int(a newintegerArghelper, so aFloat or a user
#to_intobject works; a non-coercible value, or a#to_intreturning a non-Integer, raisesTypeError);Math::DomainError(
"Numerical argument is out of domain - \"isqrt\"");big.Int.Sqrt, so Bignum arguments andresults work (
Integer.sqrt(10**400) == 10**200).Verified against ruby 4.0.6;
sqrt_specnow passes6/6. NewintegerArgat 100% coverage, the whole-suite coverage gate stays at100.0%, and a full language+core sweep shows no regressions.
🤖 Generated with Claude Code