Repository navigation
Give Float#remainder's zero the dividend's sign - #432
Merged
Merged
Conversation
A zero has a sign, and Ruby's is the dividend's, never the divisor's:
(-7.0).remainder(3.5) is -0.0 where 7.0.remainder(3.5) is 0.0, and
7.0.remainder(-3.5) is still 0.0. Checked against MRI, not reasoned.
`a - b*trunc(a/b)` reaches neither reliably, and it was wrong in both
directions:
- where it cancels, x - x is +0.0 whatever x was, so
(-7.0).remainder(3.5) answered 0.0 on every architecture, this
machine included — a plain wrong answer that nothing was asking
about;
- on loong64 under qemu the same cancellation answered -0.0 for
7.0.remainder(3.5), which has had the arch nightly red since
2026-08-12.
Saying the sign outright costs one comparison and settles both. The four
new cases fail without the change here, so the next drift is caught on
this machine rather than a nightly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
Author
|
Verified on the lane that catches it. loong64 is where the wrong sign showed, and this machine cannot reproduce that half. Both this and #431 were put on Run 32661057000 — all four green, after twelve consecutive red nights for loong64:
Worth repeating from the description: the loong64 failure was only half the defect. |
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.
A zero has a sign, and Ruby's is the dividend's, never the divisor's. Checked against MRI 3.4.5 rather than reasoned:
a - b*trunc(a/b)reaches none of that reliably, and it was wrong in both directions:On every architecture, this machine included. Where the subtraction cancels,
x - xis+0.0whateverxwas — so(-7.0).remainder(3.5)answered0.0. A plain wrong answer that no lane was asking about, because no case covered it.On loong64 under qemu, the same cancellation answered
-0.0for7.0.remainder(3.5), which has hadarch-qemu-nightlyred since 2026-08-12:Stating the sign outright —
math.Copysign(0, a)when the result is zero — costs one comparison and settles both directions at once.Proof
TestFloatRemainder, each checked against MRI first../internal/vm/green.arch-qemu-nightlyis dispatched on this branch and its result is linked below before this merges.