Repository navigation
Keep overflowing Integer receivers exact in fdiv(Float) - #274
Merged
Merged
Conversation
284km
marked this pull request as ready for review
November 25, 2026 04:43
284km
commented
Nov 25, 2026
284km
left a comment
Owner
Author
There was a problem hiding this comment.
Reviewed 6c28340. No Critical / Major / Minor findings.
Integer#fdiv(Float)with a Bignum receiver whose Float conversion overflows now divides exactly: the finite divisor is taken as its exact binary fraction (flt_rat_parts) and the quotient comes frombig_fdiv_s. NaN, ±0.0 and ±Infinity divisors keep Ruby's answers, and receivers that convert to a finite Float keep the old path. Both entry points (prim_method_raw's integer fdiv and the VBig arm) go through the same helper.- Ran on the author's build at this head (clean tree, binary newer than every
.merefile), on the evaluator andMERE_RUBY_VM=1, against ruby 4.0.10:- corpus 1113: identical output on both engines.
- Extra probes:
n.fdiv(1.0),n.fdiv(1e308),(-n).fdiv(3.0),(10**308).fdiv(0.1),(2**1100).fdiv(2.0**100),(10**400).fdiv(5e-324),n.fdiv(7e300),(10**30).fdiv(3.0)andn / 1e200: all identical.
- Suggestion (not a regression; main gives the same):
(10**500).quo(1e200)is stillInfinityon both engines, where ruby gives1.0e+300.Integer#quowith a Float argument is fdiv in ruby, so it could sharebig_float_fdivin a follow-up. - The description has the local results our merge policy asks for: corpus
--bothandMERE_RUBY_VM=1 --both897/897 with hash indexing ON and OFF, the source gates, record_hygiene, and the related upstream selections with RSS on both engines. git merge-treeagainst current main: clean. No mere-pr-review-watch inline comments.
Merging.
This was referenced Nov 25, 2026
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.
Preserve a huge Integer receiver during fdiv(Float) when converting it to a double first would overflow. The recorded test_float_fdiv failure now passes on evaluator and VM. Full local acceptance is complete: 897/897 corpus programs on both engines, with hash indexing ON and OFF.
A1: current-main numeric RED reproduction and causes
The merged inventory PR #243 records the archived report before fixes.
This branch starts from current origin/main a63e47c. The clean reference
is Ruby 4.0.10 a704b7cd95. All selections below use unchanged upstream
files, one file at a time, --seed=1 and MERE_RUBY_GC_TIGHT=1.
The actual ext/-test-/integer C sources were built separately against the
reference headers and Mere C API headers, outside the reference install.
No helper is replaced and no reference gems are installed. A direct
reference probe confirms to_bignum(0) is a real forced Bignum.
The selected test_bignum.rb cases pass 8 tests / 60 assertions on Ruby;
main fails all 8 on evaluator and VM (34 assertions reached). Selected
test_integer.rb#test_pow passes 1 test / 36 assertions on Ruby; main times
out at its existing test deadline on both engines (6 assertions reached).
No deadline, budget, assertion or test size was changed.
First cause: overflowing Integer receiver in fdiv
CRuby first converts the receiver; when that overflows, its fdiv path
converts the Float divisor to its exact binary fraction and divides the
integer magnitudes. It does not divide Infinity by the divisor. The
reference also raises ZeroDivisionError for a zero Float divisor and
FloatDomainError for an infinite divisor on this overflow path, while
preserving NaN. These controls were reproduced before editing.
Implementation, corpus and final acceptance are recorded below after
validation. The other numeric causes in the table remain separate work.
The invalid-digits-base failure was checked at its exact assertion line
840: it is the ordinary negative Bignum base, not the earlier forced-small
Bignum controls. A standalone n.digits(-n), n = 2**1024 - 1, also fails
without any C API helper. This case stays in the numeric work stream.
fdiv implementation and focused acceptance
The final O2 helper keeps the ordinary finite-receiver conversion path.
When an Integer's private Float conversion overflows, it decomposes a
finite Float divisor into its exact binary fraction and uses the existing
integer-magnitude quotient routine. It preserves NaN and the reference's
overflow-path errors for zero and infinite divisors. Both primitive entry
paths share the helper; no Ruby conversion hook is called for a builtin
Float, and no global receiver or cache is added.
Corpus 1113 covers positive/negative receivers and divisors, finite and
overflowing results, Float::MAX, signed zero, infinities, NaN, ordinary
finite conversion, integer-pair division, coercion and a saved native alias.
Its complete stdout and exit status match clean Ruby on evaluator and VM
with tight GC, on the final O2 binary.
The following unchanged upstream selections were run one file at a time,
with seed 1 and tight GC. Reference and candidate pass all rows; main's
bignum selection retains the one recorded float_fdiv failure. RSS is bytes:
Build: compiler 9dec2ff6, mgz 661a01d8, ordinary O2. Immutable binary
SHA-256 b85f3c6d04c4978b9ef856952dc76b0fc2b6cfa56fccaff553db709ab77fceb3.
The generated C passes the bracket-depth gate. The full evaluator
sh run_corpus.sh --bothand subsequentMERE_RUBY_VM=1 sh run_corpus.sh --botheach pass 897/897 programs withhash indexing ON and OFF, all source gates, and full record_hygiene.
This loop record is also checked explicitly. No full unit suite or Rails
component suite was run, and no workflow is changed.
Completed full acceptance uses the same immutable O2 binary and runtime source as this PR head. This results-only update edits the PR description without a source/record-only push, following the CI backlog policy. Hosted acceptance and owner merge review remain separate.