Repository navigation
Avoid overflow when interpolating finite opposite-sign quantiles - #301
Closed
RealBhupesh wants to merge 3 commits into
Closed
RealBhupesh wants to merge 3 commits into
RealBhupesh wants to merge 3 commits into
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.
Fixes #300
quantile,quantileSorted, andmediancan return a non-finite result when interpolating between finite, large opposite-sign values:The intermediate subtraction
value1 - value0overflows. It can also yieldNaNat an interior integer position throughInfinity * 0, for example the median of[-H, -H, H]withH = 2 ** 1023.This change uses
value0 * (1 - t) + value1 * tonly when both selected endpoints are finite and their difference overflows. Otherwise it keeps the original interpolation expression. Selection, endpoint handling, coercion, and accessor calls are unchanged; the median wrapper and index APIs are not changed. This is a narrow intermediate-overflow fix, not a claim of correctly rounded interpolation in general.The added tests cover symmetric and asymmetric opposite-sign pairs at exact dyadic weights, plus an interior integer position.
Validation on Node v22.23.4, using an isolated plain-Node adaptation:
Object.isfor 91 finite and 42 non-finite preservation cases each, including signed zero, same-sign extremes, andNaN.quantile-test.jsandmedian-test.jspass for both versions, including R-7, coercion, accessors, andOneTimeNumberchecks. The candidate's added assertions pass too.node:testand the public barrel imports with direct source imports; expected baseline and mutant mismatches are explicitly asserted. This is not a Vitest, full-suite, type-check, build, or CI result. Those checks have not been run locally.I used AI assistance to prepare this change.