Repository navigation
Conversation
…ellipk` For `m < 0` the parameter is transformed to `x = m/(m-1)`, and `1 - x` was then formed by subtraction, which cancels as `m` grows more negative. The relative error reached 2e-5 at `m = -1e15`, 5e-3 at `-3.7e15`, and `x` rounds to one below `-2^53`, so the function returned `Infinity`. Form `1 - x` as `1/(1-m)` instead. The C++ fixture for large negative values was computed through the same transformation in Boost and was itself off by up to 6e-8, which is what the 204773163-ULP tolerance and its FIXME were covering. It is replaced by a Julia runner evaluating `pi/(2*agm(1, sqrt(1-m)))` in BigFloat. Signed-off-by: Abhist17 <abhistkamle.170903@gmail.com>
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:
1 - xas1/(1-m)inmath/base/special/ellipk(JS and C), wherex = m/(m-1)is the transformed parameter form < 0, instead of subtractingxfrom one.The subtraction cancels as
mgrows more negative, and below-2^53xrounds to exactly one:m-1e101.2899219784372459e-41.2899219825792643e-41.2899219825792638e-4-1e155.899571246472065e-75.899444819017533e-75.899444819017532e-7-3.7e153.190675447053322e-73.174519615424412e-73.174519615424411e-7-1e16Infinity1.9806975105072258e-71.9806975105072255e-7-1e300Infinity3.4677405831022676e-1483.4677405831022676e-148This also explains the
FIXME: investigate the reason for this large discrepancyon the large-negative test (tolerance 204,773,163 ULPs). The C++ runner computes those fixtures with Boost through the same transformation (k = sqrt(m/(1+m))), so the expected values themselves were off by 1e-8 to 6e-8 relative to mpmath. The fixed implementation is off by 1e-16.test/fixtures/cpp/large_negative.jsonwith a Julia runner that evaluatesK(m) = π / (2 agm(1, sqrt(1-m)))in 2048-bitBigFloat. That identity holds for everym < 1without transformingm. It writeslarge_negative.json(same range as before) and a newhuge_negative.json(-1e10to-1e300). The large-negative tolerance drops from 204,773,163 to 5 ULPs, the new set passes at 4, and the FIXME is gone.ellipk( -Infinity )returningNaN, as documented.Related Issues
None.
math/base/special/ellipecallsellipk( x )with the same roundedxform < 0, and returns1below-2^53. I'll send that as a follow-up, since it depends on this.Questions
No.
Other
test.jsandtest.native.js: 17007 pass.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?