Hacker News Viewer

Approximating Hyperbolic Tangent

by jtomschroeder on 4/22/2026, 11:46:38 PM

https://jtomschroeder.com/blog/approximating-tanh/

Comments

by: raphlinus

A different approach, refining the square root based sigmoid with a polynomial, is in my blog post &quot;a few of my favorite sigmoids&quot; [1]. I&#x27;m not sure which is faster without benchmarking, but I&#x27;m pretty sure its worst case error is better than any of the fast approximations.<p>[1]: <a href="https:&#x2F;&#x2F;raphlinus.github.io&#x2F;audio&#x2F;2018&#x2F;09&#x2F;05&#x2F;sigmoid.html" rel="nofollow">https:&#x2F;&#x2F;raphlinus.github.io&#x2F;audio&#x2F;2018&#x2F;09&#x2F;05&#x2F;sigmoid.html</a>

4/23/2026, 1:07:52 AM


by: agalunar

There’s an analysis of the Schraudolph approximation of the exponential function (along with an improvement upon it) that someone might find interesting at <a href="https:&#x2F;&#x2F;typ.dev&#x2F;attention#affine-cast" rel="nofollow">https:&#x2F;&#x2F;typ.dev&#x2F;attention#affine-cast</a>

4/23/2026, 12:52:53 AM


by: mjcohen

Looks interesting. Should start with a definition of the Hyperbolic Tangent. It is only about 2&#x2F;3 of the way that the definition occurs in a discussion of computing exp(x).

4/23/2026, 12:31:18 AM