Repository navigation
Conversation
…l/erfcinv` The Boost implementation this package follows has a separate rational approximation for `18 <= sqrt(-ln(x)) < 44`, and the JSDoc already lists its error bound, but the code used the `[6, 18)` approximation for every `sqrt(-ln(x)) >= 6`. Outside its range that approximation drifts: for `x` below about `1e-140` the error grows to 1,340 ULP at the smallest subnormal. Add the `[18, 44)` rational approximation (which covers every double, as the smallest gives `27.28...`) in JS and C, generated by `scripts/evalrational.js`, and add a fixture for tiny `x` computed in 2048-bit precision.
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
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:
18 <= sqrt(-ln(x)) < 44tomath/base/special/erfcinv(JS and C), which fixes its accuracy forxbelow about1e-140.The implementation follows Boost's
erf_inv_imp, which for smallxuses a series of rational approximations inp = sqrt(-ln(x)), one each forp < 3,p < 6,p < 18,p < 44andp >= 44. The JSDoc here already lists all five error bounds, but the code stops at the third. Everyp >= 6goes through the[6, 18)approximation, and pastp = 18(x ~ 1e-141) it is extrapolating. For doubles,preaches27.28...at the smallest subnormal, so the[18, 44)branch is the only missing one, andp >= 44can't occur.Error against 2048-bit
erfcinv(Julia,SpecialFunctions) onx = 10^-kfork = 100..323, plus subnormals:develop5e-324)Changes:
scripts/evalrational.jsgains Boost'sP/Qcoefficients for the[18, 44)range (padded with zeros like the other tables). It generateslib/rational_p6q6.jsand therational_p6q6function insrc/main.c, inside newBEGIN/ENDmarkers.lib/main.jsandsrc/main.cgainY6 = 0.99714565277099609375and theq < 18/q >= 18split.x_tiny.jsonfixture (1,001 points,xlog-spaced over[1e-323, 1e-15]plus5e-324), generated by agen_tinyfunction inrunner.jlthat evaluateserfcinvin 2048-bitBigFloat, with a 2-ULP tolerance. Ondevelop, 416 of its assertions fail. With this change, all 7,013 assertions pass in bothtest.jsandtest.native.js.Related Issues
This pull request has the following related issues:
stats/base/dists/normal/quantileviaerfcinvto keep the lower tail #15615 (normal/quantileviaerfcinv), whose lower-tail fixture stops at1e-250because of this.Questions
No.
Other
runner.jlwith a currentJSON.jlfails on the existingx_1.9999..8_2.jsonblock, becauseerfcinv( 2.0 )is-Infand newerJSON.jlrefuses to write it. So I generated only the new fixture, with the samegen_tinycode, and the existing fixture files are unchanged.rational_p1q1.jstorational_p5q5.js, but only their copyright year changed, so I left them out of the diff.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code.
@stdlib-js/reviewers