Repository navigation
Raise FloatDomainError converting a non-finite Float to an Integer - #508
Merged
Merged
Conversation
Float#to_i/#to_int and #round/#ceil/#floor/#truncate without a positive
ndigits convert to an Integer, which a non-finite Float has none of:
MRI raises FloatDomainError. rbgo instead crashed on NaN#round (a
big.ErrNaN panic that escaped the RubyError recovery) and silently
returned 0 for NaN#to_i/#ceil/#floor. A shared floatToInt now raises
FloatDomainError ("NaN" / "Infinity" / "-Infinity") for the non-finite
cases and, as a bonus, returns a Bignum for a finite Float beyond a
machine word (1e20.to_i). A positive ndigits still yields a Float and
keeps NaN.
Unblocks core/float/round_spec (previously crashed → 0, now 21 passing)
and lifts to_i / truncate. Verified against MRI Ruby 4.0.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.
Float#to_i/#to_intand#round/#ceil/#floor/#truncatewithout a positivendigitsconvert to an Integer, which a non-finite Float has none of — MRI raisesFloatDomainError.rbgo instead crashed on
NaN.round(abig.ErrNaNpanic that escaped theRubyErrorrecovery, taking down the whole spec file) and silently returned0forNaN.to_i/.ceil/.floor.A shared
floatToIntnow raisesFloatDomainError("NaN"/"Infinity"/"-Infinity") for the non-finite cases and, as a bonus, returns a Bignum for a finite Float beyond a machine word (1e20.to_i). A positivendigitsstill yields a Float and keepsNaN.Conformance: unblocks
core/float/round_spec(previously crashed → 0, now 21 passing) and liftsto_i/truncate. Verified byte-for-byte against MRI Ruby 4.0.6.go test ./...green, native +wasip1/wasmbuild, gofmt clean, new code 100% covered.🤖 Generated with Claude Code