Repository navigation
Round a computed value onto zero only where its terms cancelled - #2072
Merged
Rafael-SOWNet merged 1 commit intoOct 22, 2026
Merged
Conversation
A number an evaluation produced was rounded onto zero below half the working digits outright, 1e-50 at a hundred, whatever produced it. So e^(-155) was 0 at a hundred digits, the modulus of a complex number near 1e-136 was 0 and a quotient by it NaN, and the derivative of a right antiderivative of 1/sqrt(a + i a sinh(c + d x)) at a large argument was NaN at up to two hundred digits and 1.5329 at three hundred, where it is 2.0185e-68 (1 - i). A residual of cancellation is a difference below half the working digits of its terms, and that is now the only value rounded onto zero by size: a sum of opposite signs is measured against one of its terms, and a product, a quotient, a power, a root, an exponential or a modulus, which cancel nothing, is never rounded onto zero; a cosine's or a sine's residual is measured against the modulus it multiplies. sin(pi), e^(i pi) + 1 and sqrt(2) sqrt(3) - sqrt(6) are still 0, and #561's matrix times its inverse is still the identity. A quotient of decimals is divided to the working precision's places, as it was, and divided again to its digits where that lost them: 3.5e-68 kept thirty-three digits, and a quotient below 1e-100 was 0. The derivative is right from two hundred digits. Its terms cancel in their sixty-eighth digit, so below about twice that the difference is under half the digits and reads as a residual: at a hundred it is the real part without the imaginary one, where it was NaN. The scale is either term, which costs nothing, where comparing the two rescaled a mantissa: allocation per evaluation is master's, measured on the kernel gate's polynomial at a hundred and at fifteen digits. Part of #1944. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
This was referenced Oct 22, 2026
Rafael-SOWNet
added a commit
that referenced
this pull request
Oct 22, 2026
A function's value was rounded onto zero below half the working digits outright. That floor is for the residual a function leaves at its own zeros: sin(pi) evaluates to about 1e-100. That residual is relative to the argument, though, and a function of an exact small argument cancels nothing, so sin(10^(-60)), arctan(10^(-60)), erf(10^(-60)) and Si(10^(-60)) were all 0 at a hundred digits. The sine, cosine, tangent, logarithm, arcsine, arccosine and arctangent of a real argument, the error functions, and Si and Shi now create their value at the argument's scale, as #2072 made arithmetic do with what cancelled. sin(pi), sin(100 pi), cos(pi/2), tan(pi) and arccos(1) are still 0. The argument is passed as it is and its modulus taken only on the path that tests for a residual, so the kernel workloads allocate as before. sinh(10^(-60)) is still 0: it is evaluated from e^(10^(-60)), which is 1 within half the digits, a cancellation the working precision cannot resolve. Fixes #2074. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Part of #1944. Follows #2066.
The defect. A number an evaluation produced was rounded onto zero below half the working digits outright,
1e-50at the default hundred, whatever had produced it. On 2.6.0:e^(-155)was0at a hundred digits.1e-136was0, and a quotient by that modulus was NaN.1/sqrt(a + i a sinh(c + d x))atx = 227283/1250was NaN at up to two hundred digits. At three hundred digits it was1.5329…, where it is2.0185e-68 (1 - i).The change. A residual of cancellation is a difference below half the working digits of its terms. That is now the only value rounded onto zero by size.
sin(pi),e^(i pi) + 1andsqrt(2) sqrt(3) - sqrt(6)are still0. Incorrect work with large values in the matrix #561's matrix times its inverse is still the identity.3.5e-68kept thirty-three digits, and a quotient below1e-100was0.What it does not do. The derivative above is right from two hundred digits. Its terms cancel in their sixty-eighth digit, so below about twice that many digits the difference is under half of them and reads as a residual. At a hundred digits it comes out as the real part without the imaginary one, where it was NaN. An evaluation that cancels more digits than half the working precision cannot be told apart from exact cancellation without carrying an error bound through the arithmetic.
Allocation. It matches master's: 12,731 B/op against 12,743 on the kernel gate's polynomial at a hundred digits, and 12,077 against 12,077 at fifteen. The scale is either term, which costs nothing, where comparing the two rescaled a mantissa. A quotient is divided again only when it lost digits, where dividing every quotient to digits cost 680 bytes more each.
AResidualIsZeroOnlyWhereItCancelledTest, against mpmath, covers:Results:
c614b2c8), is 48,305 of 48,305, with no row moved and no answer's allocation grown.🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura