Repository navigation
tanh and coth of a large number are their limits - #2305
Merged
Rafael-SOWNet merged 1 commit intoOct 31, 2026
Merged
Conversation
tanh and coth are spelled (e^(2x) - 1) / (e^(2x) + 1) and its reciprocal. Past the range of the decimals both sides are infinite, so tanh(5568) and coth(332640) evaluated to NaN, where they are 1; past a double's, tanh(400) compiled to NaN in all three compilers. The negative side was right only because e^(-11136) is 0. A quotient of one power plus two constants, (b^v + c1) / (b^v + c2), is the same value as 1 + (c1 - c2) / (b^v + c2) wherever it has one, and the second does not divide an overflow by an overflow. ExponentialQuotients writes it so. Evaluation asks for it where both sides of a quotient come out infinite, and the compilers' pre-pass writes every such quotient so, since a double cannot tell an overflow from an infinity. At +oo it is the limit, 1, as tanh(-oo) was already -1 and arctan(+oo) is pi/2. Respelling tanh itself as 1 - 2/(e^(2x) + 1) was measured and not taken: 21 tests change, nearly all integrals of hyperbolic functions the integrator reads in the quotient form. HyperbolicTangentPastTheRangeTest takes both sides evaluated and compiled, the infinities, and the compiled values inside the range, near 0 as well, against Math.Tanh. Seven of its cases fail on master. compilesweep's 112 findings are the same list on master and here. The suite, the trio, F#, AOT and the eight harnesses pass. Fixes #2254. Co-Authored-By: Claude Opus 5.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 #2305 +/- ##
==========================================
+ Coverage 86.74% 86.76% +0.02%
==========================================
Files 310 311 +1
Lines 67973 67995 +22
Branches 19744 19744
==========================================
+ Hits 58961 58994 +33
Misses 4880 4880
+ Partials 4132 4121 -11
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Rafael-SOWNet
deleted the
tanh-and-coth-of-a-large-number-are-their-limits
branch
October 31, 2026 21:49
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.
tanhandcothare spelled(e^(2x) - 1) / (e^(2x) + 1)and its reciprocal. Past the decimals' range, or a double's, both sides are infinite and the quotient was NaN.tanh(5568),EvaledandEvalNumericalNaN1coth(332640)NaN1tanh(+oo)NaN1, astanh(-oo)was already-1andarctan(+oo)ispi / 2tanh(x)compiled at 400 (FastExpression, LINQ overdoubleand overComplex)NaN1(b^v + c1) / (b^v + c2)has the same value as1 + (c1 - c2) / (b^v + c2)wherever it has one, and the second form doesn't divide an overflow by an overflow.ExponentialQuotientswrites it that way. Evaluation uses it only where both sides come out infinite. The compilers' pre-pass always writes it so, since a double can't tell an overflow from an infinity.tanhitself was measured and not taken. As1 - 2/(e^(2x) + 1), 21 tests change, nearly all integrals the integrator reads in the quotient form.compilesweepgives the same 112 findings on master and here. 7 of the new test's cases fail on master.Fixes #2254.
🤖 Generated with Claude Code