Conversation
The iteration has two representation floors but only tested one: the correction falling below the resolution of `x`. The residual `erfc(x) - y` cannot go below the resolution of `erfc(x)`, and that noise is amplified into the step by `1 / erfc'(x) = sqrtπhalf * exp(x^2)`. Whenever `sqrtπhalf * exp(x^2) * eps(y) > 2eps(x)` the tested condition is unattainable and the iterates end up in a two-cycle. Check the residual as well. `erfinv` is affected in the same way for `y` close to ±1. Fixes #557 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #559 +/- ##
=======================================
Coverage 94.67% 94.67%
=======================================
Files 14 14
Lines 3023 3025 +2
=======================================
+ Hits 2862 2864 +2
Misses 161 161
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #557.
The iteration has two representation floors, but only one was tested: the correction falling below the resolution of
x. The residualerfc(x) - ycannot go below the resolution oferfc(x), and that noise is amplified into the step by1 / erfc'(x) = sqrtπhalf * exp(x^2). Wheneversqrtπhalf * exp(x^2) * eps(y) > 2eps(x)the tested condition is unattainable and the iterates end up in a two-cycle. So the residual is now checked as well.This affects roughly 1–3% of random arguments at every precision.
erfinvis affected in the same way foryclose to ±1 (erfinv(big"0.96")hangs on master), so it is fixed too.2eps(y)rather thaneps(y): whenerfc(x)sits one binade abovey, the smallest attainable nonzero residual is already2eps(y).Verified with 25000 inversions over precisions 64/128/256/512/1024 in four regimes (mid-range,
y → ±1,y → 0,y → 2): no hangs, round-trips within8eps(BigFloat), and accuracy unchanged against aprecision + 128reference.🤖 Generated with Claude Code