CKTIS / C
tanh — hyperbolic tangent
The tanh function from <math.h> computes the hyperbolic tangent of a double argument and returns a double result.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <math.h>
double tanh(double x);tanh(x) computes the hyperbolic tangent, not the ordinary tangent tan(x). Its argument and result have type double; <math.h> provides its declaration.
Mathematically, the result for a finite argument lies between −1 and 1, but rounding can produce an endpoint. A range error occurs when nonzero x is too close to zero.
Under Annex F (IEC 60559), tanh(±0) returns ±0, and tanh(±∞) returns ±1. Do not assume these guarantees for every C implementation. The float and long double variants are tanhf and tanhl, respectively.
Examples
#include <math.h>
#include <stdio.h>
int main(void)
{
double x = 0.0;
double result = tanh(x);
printf("tanh(0) = %.1f\n", result);
return 0;
}
Result
tanh(0) = 0.0
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.