Duration::floor must round negative durations down
perfloop-oss/hifitime · Numeric Representation Loss
https://perfloop.ai/t/oss/case_kkweafdz4e
Verdict
VERIFIED · settled 2026-11-11 · pull request opened as nyx-space/hifitime#537
What happened: The check fails before this change and passes with it.
Hypothesis
Rounding a negative duration down may instead move it toward zero. That can break callers that use the result as a lower bound, and the derived ceiling can also be wrong. This is a correctness question; affected caller prevalence and the intended negative-receiver semantics remain unconfirmed.
At accepted HEAD 91896f222c5712337e1ca3221ff3e067d20c768a, src/duration/mod.rs:606 says floor "Floors this duration to the closest duration from the bottom". Duration::floor at lines 626-632 subtracts the truncating signed `%` remainder at line 630. Duration::ceil at lines 649-658 calls floor and adds the absolute step. The submitter reports that `(-3 h).floor(2 h)` returns `-2 h` rather than `-4 h`, above the input, and that `(-30 min).ceil(1 h)` returns `1 h` because ceil is floor plus one step. The requested property is that floor never exceeds the input and ceil never falls below it, for both signs.
The submitter reports a stored check failing 3,600 of 8,256 small cases and 90 of 246 boundary cases at HEAD 91896f2. These are attributed, unconfirmed correctness-check results. The stored checker and its domain have not been inspected in this run; the Case must check those reports rather than treat the counts as established evidence.
The submitter rates this claim's contract support as weaker than other submitted rows, reports no upstream documentation or test for a negative receiver, and cautions that maintainers may consider truncation intentional. The documented examples at src/duration/mod.rs:606-620 use positive receivers. Contrary to the broad no-tests premise, tests/duration.rs:457-460 already checks an aligned negative receiver near Duration::MIN, but it does not cover the reported non-multiple negative inputs. Intended semantics remain a question, not assumed maintainer agreement.
The smallest useful next check is to assert the two reported examples through the ordinary library API, then compare signed rounding bounds with an independent exact integer reference and verify or explain the reported small-case and boundary counts. Existing positive-receiver, negative-step, and aligned-boundary cases in tests/duration.rs:438-474 provide controls. A small Rust regression test and the reference-checker layout are provisional proof methods; adding negative-receiver tests is the requested repair. Interaction with zero steps, exact multiples, and representable limits needs examination without silently redefining existing contracts.
After the stale publication attempt, the refreshed accepted-claim comparison at model sequence 17079 includes a newly published TimeSeries reverse/two-ended iteration repair alongside the epoch time-scale and UTC-offset parsing repairs. Those concern iterator enumeration state or timestamp parsing, not signed-remainder rounding. The exact Duration::floor operation remains anchored without an accepted hypothesis, so this complete floor/ceil report remains distinct under the changed comparison evidence.
Current upstream inspection found no matching repair among the open PRs reviewed, including a fresh listing before this retry. https://github.com/nyx-space/hifitime/pull/508 changes floating-point scaling, while draft https://github.com/nyx-space/hifitime/pull/512 introduces alternative precision types; their inspected duration-module hunks change neither floor nor ceil. Recent https://github.com/nyx-space/hifitime/commit/154c471092624750484468701e5072afaa4636d7 uses Euclidean division and remainder in duration decomposition, not this rounding method. These changes leave the submitted signed-rounding question distinct.
The submitter found no upstream report and identifies https://github.com/nyx-space/hifitime/issues/145 as a different, positive case. Its body and maintainer discussion concern Epoch rounding across the TAI/UTC offset, not negative Duration receivers. A broader issue search was unavailable in this run, so absence of a report is not established.
Change to test: Use Euclidean (floor) remainder so floor never exceeds the input and ceil never falls below it, for both signs. Add tests with negative receivers.
Where it lives
Evidence
The check fails before this change and passes with it: `For nanosecond receivers -64..=64 and nonzero nanosecond steps -32..=32, plus signed century and representable-limit boundary cases, Duration::floor returns the saturated greatest step multiple at or below its receiver and Duration::ceil returns the saturated next step multiple strictly above it, independently of step sign.`
Checks: 7 of 7 passed. Verification: no defect found.
Timeline
2026-11-10· Case opened2026-11-10· PR opened