Math and trigonometry functions

TANH

Close: 58 of 39,031 recorded answers differ in the last bits, worst 1 ULP

Everything else matches (39,028 in the answer bank and 3 workbook cells). Last-bit means a finite number within 16 ULP of Excel's. How we measure this · See the Rust code

Local names in 40 languages
LanguageName in Excel
ArabicTANH
BulgarianTANH
CzechTGH
DanishTANH
GermanTANH
GreekTANH
English (Australia)TANH
English (United Kingdom)TANH
English (United States)TANH
SpanishTANH
EstonianTANH
FinnishTANH
FrenchTANH
HebrewTANH
CroatianTANH
HungarianTANH
IndonesianTANH
ItalianTANH
JapaneseTANH
KoreanTANH
LithuanianTANH
LatvianTANH
NorwegianTANH
DutchTANH
PolishTANH
Portuguese (Brazil)TANH
Portuguese (Portugal)TANH
RomanianTANH
RussianTANH
SlovakTANH
SlovenianTANH
Serbian (Latin)TANH
SwedishTANH
ThaiTANH
TurkishTANH Denklemi
UkrainianTANH
VietnameseTANH
Chinese (Simplified)TANH
Chinese (Hong Kong)TANH
Chinese (Traditional)TANH

Names from Microsoft's support site.

What it does

TANH(number)

TANH(number) is the hyperbolic tangent:

tanh x  =  sinh x / cosh x  =  (e^x - e^(-x)) / (e^x + e^(-x))  =  (e^(2x) - 1) / (e^(2x) + 1)
  • Domain: all real numbers. No poles, no branch cuts, no excluded points. tanh is meromorphic with poles only at odd multiples of i*pi/2 — nowhere on the real line. This is the sharpest contrast with TAN, which has a pole every pi.
  • Range: the open interval (-1, 1). Strictly increasing, hence a bijection from R onto (-1, 1), which is why ATANH has domain (-1, 1) and blows up at both ends.
  • Parity: odd.
  • Asymptotes: tanh x -> +1 as x -> +infinity and -> -1 as x -> -infinity, and the approach is exponential: 1 - tanh x ~ 2 e^(-2x).
  • Series about zero: tanh x = x - x^3/3 + 2 x^5/15 - 17 x^7/315 + ..., radius of convergence pi/2 (the distance to the nearest complex pole). The coefficients are those of tan with alternating signs, which is the series form of tanh x = -i tan(ix).
  • Identity: 1 - tanh^2 x = sech^2 x, the hyperbolic counterpart of the derivative relation for tan.

Microsoft's article gives the signature and states the defining formula. Retrieval of that page for this entry was blocked by the upstream host (HTTP 403), so the documented content is stated here as documented behaviour and should be re-checked against the live article. The mathematics above is from the standard literature, not from the article.

Arguments

ArgumentMeaningDefault
numberAny real number. Required.—

No units. TANH is not an angle function and nothing in the RADIANS/DEGREES apparatus applies to it.

Try it

Input cells (optional)

Example: {"B2": 3, "B3": 4}. A1 holds the formula. Other cells need values before a formula can read them.

Enter a formula, then calculate.

Runs locally in your browser with OneCalc. Its answer may differ from Excel. Use English function names and commas between arguments.

Quirks

Result and edge cases

Returns Number, always in (-1, 1) mathematically — and in floating point, exactly 1 or -1 for arguments beyond the saturation point, because 1 - 2e^(-2x) rounds to 1 once the correction falls below half an ULP of 1.

Small arguments round-trip: for |x| small enough that x^3/3 is negligible, the correctly rounded tanh x is x, so subnormals pass through.

Errors

ErrorConditionSource
#VALUE!The argument does not convert to a numberShared coercion rules
propagatedAn error value in the argument is returned unchangedShared coercion rules

How to implement

Numerical notes

TANH is the well-conditioned member of its family, but there is exactly one way to get it badly wrong and it is the obvious way.

Do not compute TANH as SINH(x)/COSH(x). Both intermediates overflow at a moderate argument while their ratio remains a perfectly ordinary number near 1. A naive quotient produces #NUM!, an infinity, or a NaN — depending on the host's overflow policy — for arguments where the answer is simply 1. The same objection applies to (exp(x) - exp(-x))/(exp(x) + exp(-x)).

The standard three-band scheme (Cody & Waite; fdlibm's tanh):

  1. Tiny |x|: return x (with the inexact flag raised where the platform cares), because the correction is below rounding.
  2. Small to moderate |x|: use expm1. With t = expm1(2|x|), tanh|x| = t/(t + 2); or with t = expm1(-2|x|), tanh|x| = -t/(t + 2). The expm1 form is what keeps relative accuracy near zero, where the direct exponential quotient would cancel 1 against 1.
  3. Large |x|: return 1 (with the sign applied). There is a well-defined threshold above which the correctly rounded result is exactly 1, and computing anything at all beyond it is wasted work — and, if done naively, dangerous.

Near-zero cancellation, stated precisely. In (e^x - e^(-x))/(e^x + e^(-x)) the numerator suffers the same total cancellation as in SINH: both exponentials tend to 1 and their difference is 2x. The denominator is fine. So the relative error of the naive form grows without bound as x -> 0, exactly where the function is most linear and a user is most likely to trust it. The expm1 reformulation is not an optimization; it is the difference between a correct and an incorrect function on a large part of its useful domain.

Symmetry. Odd function: compute on |x|, apply the sign. An implementation that does so gets exact antisymmetry for free.

Why TANH is easy where TAN is hard. There is no argument reduction. There is no pi. There is no cancellation in the reduced argument because there is no reduced argument. Every difficulty TAN has comes from mapping the input into a fundamental domain, and TANH has no fundamental domain to map into. This is worth stating because the two functions are usually taught as siblings, and numerically they have almost nothing in common.

Rust code

Show the CalcFunc source of this function

Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.

TANH · 3 lines · calc-func/src/catalogue/math.rs on GitHub
21 tanh "TANH" (1, 1) [V "number"] |s, a, sv| {
    raw(s, a, ExcelRealPolicy::SATURATE_SIGN, k::tanh::tanh_kernel)
}

Kernels shared with other functions

Argument and result plumbing

  • num catalogue/kit
  • out catalogue/kit

No implementation has been published with a Handbook test suite for this function.

Version differences

The recorded environments below distinguish a reading from a same-input comparison. Counts describe captured inputs in each environment; overlapping captures and comparisons are not totals of unique worksheet calls.

Excel 16.0 buildPlatform and CPUCaptured inputs
19929Windows, bitness not recorded, CPU not recorded42
20430Windows, 64-bit, CPU not recorded39,028
  • XC-TANH-001: build 19929 versus build 20430; 1 same-input pairs, 0 differing answers. Compared axes: excel-build. Numeric answers were compared by their recorded binary64 bits; other answers by typed value.

Agreement on these compared inputs does not establish agreement on unmeasured inputs.

Recorded environments and comparison details.

Excel 16.0 build 19929

Windows, bitness not recorded, CPU not recorded

42 captured inputs are indexed for this environment. Capture dates are not recorded. This is a reading count, not a comparison with another build.

Excel 16.0 build 20430

Windows, 64-bit, CPU not recorded

39,028 captured inputs are indexed for this environment. Capture dates: 2026-09-29 to 2026-09-29. This is a reading count, not a comparison with another build.

Alternatives

Relationships

  • SINH and COSH — the numerator and denominator of the defining quotient. Note that TANH is well behaved precisely where SINH overflows: the two exponentials that overflow individually cancel in the ratio.
  • ATANH — the inverse, ATANH(y) = ln((1+y)/(1-y))/2, with domain (-1, 1) and poles at both endpoints. The saturation of TANH and the singularity of ATANH are the same fact seen from two sides: once TANH has rounded to 1, the round trip through ATANH is lost.
  • TAN — the circular sibling, tanh x = -i tan(ix). Bounded and pole-free versus unbounded and pole-ridden.
  • SECH — 1 - TANH^2, and the reciprocal of COSH.
  • Confused with: TAN, by name; and SIGN, by shape, since TANH of a large argument is a smooth saturating stand-in for the sign function. That resemblance is the reason TANH is the classical neural-network activation.

Named variants

No named variants are recorded yet.

Suggest a correction or contribute an implementation · For agents