Repository navigation
fix: avoid NaN near negative poles in math/base/special/digamma and polygamma - #17133
Open
masrulmallick014-cpu wants to merge 1 commit into
Open
masrulmallick014-cpu wants to merge 1 commit into
masrulmallick014-cpu wants to merge 1 commit into
Conversation
…nd `polygamma` Compute the remainder for the reflection's `tan` term from `x` itself, before reflecting. `1 - x` is not always exact, so taking the remainder after reflecting can lose the distance to the nearest pole, which returns `NaN` or inaccurate values near negative integers. Apply the same change to `polycotpi` in `polygamma`, which took `cospi` from the rounded `1 - x`. This mirrors the upstream Boost fix (boostorg/math#1668). --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
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.
Resolves #17132
Description
This pull request:
math/base/special/digamma(JavaScript and C) so that, forx <= -1, the remainder for the reflection'stanterm is computed fromxitself before reflecting, instead of from the rounded1 - x. This removes theNaNresults and large errors near negative integers (e.g.,digamma( -1.0000000000000002 )anddigamma( -4503599627370495.5 )returnedNaN). As in Boost, the term is evaluated as-pi * tan( pi * ( 0.5 - rem ) )for0.25 <= rem <= 0.75, wheretanwould otherwise lose digits.polycotpiinmath/base/special/polygamma(JavaScript and C) to takecospifrom the unrounded argument, as it already does forsinpi.digammamust not returnNaNnext to the negative integers-1to-1000, and both functions are checked against mpmath values at the examples from the issue.xinpolygammafrom 2858 and 2773 ULP to 767 and 588 ULP.Related Issues
This pull request has the following related issues:
math/base/special/digammaandpolygammareturnNaNor wrong values near negative integers #17132Reference Packages
This pull request followed these packages:
math/base/special/digammafdigammafalready does.tanterm and thepolycotpichange follow the upstream Boost fix (Fix new numerical error in digamma and polygamma due to removal of promotion boostorg/math#1677). The expected test values were computed with mpmath at 80 digits.Questions
No.
Other
1 - x: since #1554, double gives a pole error at non-integer x and loses digits at ordinary negative x boostorg/math#1668, Fix new numerical error in digamma and polygamma due to removal of promotion boostorg/math#1677.develop(5 failures indigamma, 16 inpolygamma) and pass with this change.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
I applied the changes, ran the JavaScript and native tests locally, and checked the results myself.