Repository navigation
Conversation
…antile` `1 - 2|p-0.5|` rounds away the low-order bits of a small `p`: the lower tail lost precision below `p ~ 1e-8` and returned `-Infinity` for `p < 2^-54`. Use `ln(2p)` and `ln(2(1-p))`, which are exact up to the logarithm.
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
5 of 7 tasks
This branch has not been deployed
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.
Description
This pull request:
stats/base/dists/laplace/quantilefrompitself (JS, factory and C).The function computed
mu - b*signum(p-0.5)*ln(1 - 2|p-0.5|). Forp < 0.5,1 - 2|p-0.5|is2p, but forming0.5 - pfirst rounds away the low-order bits of a smallp. Precision degrades belowp ~ 1e-8, and forp < 2^-54the result is-Infinity:It now returns
mu + b*ln(2p)forp < 0.5, andmu - b*ln(2(1-p))otherwise. Both products are exact, and1 - pis exact forp >= 0.5. The upper tail was already accurate, sincep - 0.5is exact there. This also drops thesignumandabsdependencies.Tests:
runner.jlgains agen_tailsfunction. It evaluates the textbook formulamu - b*sign(p-0.5)*ln(1 - 2|p-0.5|)in 2048-bitBigFloatand writestails.json:plog-spaced over[1e-300, 0.1],1-plog-spaced over[1e-16, 0.1].muis0, so the test isolates the tail and not the rounding ofmu + .... The new tests intest.quantile.js,test.factory.jsandtest.native.jspass at the existing 1-ULP tolerance. Ondevelop, 498 of them fail. The existing fixtures still pass unchanged.Related Issues
None.
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code. I found the bug by scanning
stats/base/distsforln( 1.0 - ... ).@stdlib-js/reviewers