Skip to content

Raise FloatDomainError converting a non-finite Float to an Integer - #508

Merged
tannevaled merged 1 commit into
mainfrom
feat/float-domain-error
Aug 30, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/float-domain-error

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

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, taking down the whole spec file) 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.

Conformance: unblocks core/float/round_spec (previously crashed → 0, now 21 passing) and lifts to_i / truncate. Verified byte-for-byte against MRI Ruby 4.0.6. go test ./... green, native + wasip1/wasm build, gofmt clean, new code 100% covered.

🤖 Generated with Claude Code

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>
@tannevaled
tannevaled merged commit a203900 into main Aug 30, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/float-domain-error branch August 30, 2026 14:59
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