Numerically stable hyperbolic tangent
Commonly you divide the domain up into different accuracy,stability regimes and apply a different approximation within each.
For $|x|&lt;1$ you can use a polynomial approximation, like Chebyshev. For $1&lt;|x|\leq E$, $E$ depending on implementation of the formula, you can use a related formula to the one you described.
For $|x|&gt;E$ you can use $\tanh(x) \approx sign(x).$
More details here from a documented implementation.