Repository navigation
Conversation
Member
Author
|
@NAThompson suggested adding compensated arithmetic as well. These are the resulting ULPs plots for this PR vs develop:
|
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.



Problem
digammaandpolygammareflect negative arguments through1 - x, and both took the trigonometric part of the reflection from1 - xafter it had been rounded. Whenever1 - xis inexact, the cotangent (or its derivative) is evaluated at a different point than the one asked for. Before #1554doublewas evaluated inlong double, where1 - xis exact for these inputs, so this only became visible once promotion was turned off.long doubleitself has always been affected.Two symptoms:
x, when1 - xrounds to an integer (for exampledigamma(-1 - eps)anddigamma(-4503599627370495.5)).x(45 ulps atx = -3.5520310993343904).Fix
digamma.hpp, both overloads: the remainder fortanis taken fromx - floor(x), which is exact, and the pole check is done before reflecting.detail/polygamma.hpp:poly_cot_pitakescos_pifrom the argument that was not rounded, as it already did forsin_pi.Three things go beyond the change proposed in the issue:
integral_constant<int, 0>)digammaoverload assignedresult =in its integer and half-integer special cases, which discarded the reflection term. That was unreachable while a rounded integer was reported as a pole. The special cases are now summed separately and added.pi / tan(pi / 2).xrather than1 - (1 - x).Results
The reproducer from the issue, x86-64 with 80-bit
long double:digamma(-3.5520310993343904)polygamma(4, -3.5520310993343904)polygamma(3, -4503599627370495.5)digamma(-4503599627370495.5)long double polygamma(3, -(2^63 - 0.5))A sweep of 296 doubles of the form
-(2^k - r)against a 100 digitcpp_bin_floatreference:digammapolygamma, n = 2, 3, 4trigammawas already correct and is unchanged.Tests
test/git_issue_1668.cpprunsfloat,double,long doubleandreal_conceptunder a policy with promotion off, so every type is evaluated at its own precision. It covers:1 - xrounds to an integer.1 - xrounds to a small half-integer, which exercises the half-integer branch of the generic overload.Every numeric check fails on develop except
polygamma(24, x), which guards the sign of the cosine.Run locally:
test_digamma,test_polygamma,test_trigammaand the new test with b2 on arm64 macOS, and the new test in Docker on x86-64, i386, arm32, arm64, s390x, ppc64le and ppc64 with gcc and clang. Not run locally: MSVC, and the CUDA and NVRTCdigammatests.Remaining limits
digammathe result is still off by hundreds of ulps indouble(245 atx = -4.652). The two reflection terms cancel there, and promotion used to hide it on x86. Fixing it needs extra precision and is not attempted here.Closes: #1668
Once this cycles green I will ask to cherry pick it onto the 1.93 beta since we don't want to ship this new numerical error