Repository navigation
Conversation
…cdf` `1 - p` rounds away the low-order bits of `p`, and `1 - (1-p)^(x+1)` then cancels. For `p < 2^-53` the function returned `0`. Use `-expm1( (x+1) * log1p(-p) )` and generate the fixtures from the textbook formula in extended precision.
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
5 of 7 tasks
0PrashantYadav0
approved these changes
Oct 8, 2026
| gen( x, p, "small_p.json" ); | ||
|
|
||
| # Tiny `p`: | ||
| x = rand( 1000 ) .* 100.0; |
Member
There was a problem hiding this comment.
Non-blocking: with x <= 100, every tiny_p case with p < 2^-53 gives a result below 1e-14, so results of order 1 aren't tested (e.g. cdf( 1e20, 1e-20 ) is 0.632, develop gives 0). Worth adding a few cases with x near 1/p? x = rand( 1000 ) .* 3.0 ./ p passes at 1 ULP.
…ic/cdf` Per review: every existing tiny-`p` case had a result below 1e-14, so CDF values of order 1 (`cdf( 1e20, 1e-20 ) = 0.632`; develop gives 0) weren't tested. Adds `tiny_p_large_x.json` with `x` up to `3/p`, at 1 ULP.
Contributor
Author
|
@0PrashantYadav0 good idea, added in 9149c8b: |
0PrashantYadav0
approved these changes
Oct 9, 2026
Member
|
LGTM |
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/geometric/cdfas-expm1( (x+1) * log1p(-p) )instead of1 - pow( 1-p, x+1 )(JS, factory and C).Forming
1 - prounds away the low-order bits ofp, and subtracting(1-p)^(x+1)from1then cancels. Forp < 2^-53the CDF is0at everyx, and for smallponly a few digits are right:planck/cdfalready uses the same-expm1(...)form.Fixtures and tests:
runner.jlnow evaluates the textbook formula1 - (1-p)^(floor(x)+1)in 2048-bitBigFloatinstead of callingDistributions.cdf, which computes in double precision and had the same cancellation.Distributionsis dropped fromREQUIRE.small_p.jsonandlarge_p.jsonare regenerated with the same input ranges.developis off by up to 7,134 ULP onsmall_p.json(p < 0.5). With this change, every fixture passes at 1 ULP in JS and native, so thesmall_ptolerance goes from 20 to 1.tiny_p.jsonwithplog-spaced over[1e-300, 0.1]andxin[0, 100], tested at 1 ULP.develop, 1,192 of the 3,012 assertions intest.cdf.jsfail. With this change they all pass.Related Issues
None. It's the same
1 - ploss as #15762, #15763 and #15764.Questions
geometric/logcdfcomputeslog1p( -pow( 1.0 - p, x + 1.0 ) )and has the same problem. I'll send it separately.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 reading the
stats/base/distsfunctions for1 - pcancellation.@stdlib-js/reviewers