Hyperbolic tangent calculator
Enter a number x and get tanh(x), with the formula it comes from.
Decimals may use a point or a comma. A sum works too, such as 2^10 or sqrt(2).
Fill in the fields; the answer appears here straight away.
How it's worked out
How it works
-
Enter the values
Type the numbers or the formula. Decimals may use a point or a comma. No idea? Click Fill in an example.
-
Instant answer
The answer appears as you type, with the most important intermediate values.
-
See the working
Under "How it's worked out" you see the steps, handy for checking your own calculation.
Definition
tanh(x) = sinh(x) / cosh(x) = (eˣ − e⁻ˣ) / (eˣ + e⁻ˣ). The result always lies between −1 and 1: it approaches 1 for large x and −1 for very negative x.
Where it is used
Because of that S-shape, tanh is a classic activation function in neural networks. It also describes the speed of a falling object with air resistance over time. See also sinh and cosh.
Values to compare with
| x | tanh(x) |
|---|---|
| 0 | 0 |
| 0.5 | 0.4621 |
| 1 | 0.7616 |
| 2 | 0.9640 |
| 5 | 0.9999 |
Why neural networks use it
Tanh squeezes any input into the range −1 to 1 and is centred on zero, which keeps outputs balanced. Its slope is largest near zero and flattens for large inputs, which is also why networks with tanh can learn slowly when values saturate. The derivative is neat: 1 − tanh²(x).
Falling with air resistance
An object that falls through air approaches a terminal speed. Its speed over time follows v = vt · tanh(g t / vt), which rises almost linearly at first and then levels off at v_t. It is built from sinh and cosh, and its inverse, artanh(x) = ½ ln((1 + x) / (1 − x)), can be evaluated with the logarithm calculator.
Frequently asked questions
What values can tanh take?
Any value strictly between −1 and 1. For large x it approaches 1 without reaching it, and for very negative x it approaches −1.
How does tanh relate to the sigmoid function?
The logistic sigmoid is σ(x) = (1 + tanh(x / 2)) / 2. Tanh is the same S-curve, stretched to run from −1 to 1 instead of 0 to 1 and centred on zero.
What is tanh(0)?
Zero. sinh(0) = 0 and cosh(0) = 1, so tanh(0) = 0 ÷ 1 = 0.
Why does tanh(20) show as 1?
The true value is 1 minus a number so small that it vanishes in the displayed digits. Mathematically tanh never equals 1.