Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve numerical stability of tanh#54

Open
jamiemlaw wants to merge 1 commit into
rawify:main from
jamiemlaw:tanh
Open

Improve numerical stability of tanh #54
jamiemlaw wants to merge 1 commit into
rawify:main from
jamiemlaw:tanh

Conversation

@jamiemlaw

@jamiemlaw jamiemlaw commented May 21, 2026

Copy link
Copy Markdown

Fixes #44

The tanh function was computing sinh(a) / cosh(a), which for large inputs was performing an Infinity / Infinity. This PR rewrites the function to use tanh(a) directly, avoiding that division.

I added an extra test to the suite to verify that the results are correct. In doing so, I realised that it also improved the numerical accuracy of the test computing tanh(1 + 3i), so I had to update it accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Overflow encountered with tanh function for large numbers

1 participant

AltStyle によって変換されたページ (->オリジナル) /