Repository navigation
fix(extremum): preserve subsecond distance ordering - #407
Merged
gouguoyin merged 2 commits intoNov 23, 2026
Merged
Conversation
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.
ClosestandFarthestcurrently compareDiffAbsInSeconds, which truncates distances to whole seconds. This treats distinct fractional distances as ties and keeps the wrong candidate.For a base at
13:14:15.900, candidates at.990and.910are 90ms and 10ms away.Closest(farther, nearer)currently keeps the 90ms candidate;Farthest(nearer, farther)keeps the 10ms candidate.Compare absolute wall-clock distances as seconds plus nanoseconds, normalizing a negative nanosecond remainder by borrowing one second. This retains precision without
time.Durationsaturation on distant dates. True equal-distance ties still keep the first candidate; invalid-input propagation and selected pointer identity are unchanged.Behavior change: cases that were false ties after whole-second truncation now select the actual closest/farthest candidate. This does not change
DiffInSecondsorDiffAbsInSeconds. Their intended whole-second behavior from #379 remains untouched. The interval-bound validation in open #406 is separate; this branch is based on clean upstream master, not that PR.Regression tests cover fractional future/past distances, second-boundary borrowing, opposite sides, nonzero whole-second false ties, one-nanosecond differences and zero distance. Controls cover genuine ties in both orders, different locations and distances beyond
time.Duration's range.Validation on Linux/amd64 for the reviewed tree:
-vet=off, matching the existing minimum-version workflow's handling of pre-existing multiple%wverbs. Go 1.26.6 vet passes separately.GOGC=20,-p 1and-gcflags=all=-lto reduce compilation memory pressure. The Go 1.26.6 build used ordinarygo build ./....math/bigpublic-API oracle checked 8,000 generated selections for both extrema, 16,000 checks: 6,292 base mismatches and zero candidate mismatches.git diff --checkpass.No golangci-lint, remote CI, cross-platform or performance result is claimed.