Skip to content

Improve numerical stability of tanh#54

Open
jamiemlaw wants to merge 1 commit into
rawify:mainfrom
jamiemlaw:tanh
Open

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

Conversation

@jamiemlaw
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overflow encountered with tanh function for large numbers

1 participant