# tanh() function in C++ STL

The tanh() is an inbuilt function in C++ STL which returns the hyperbolic tangent of an angle given in radians.

Syntax :

```tanh(data_type x)
```

Parameter :The function accepts one mandatory parameter x which specifies the hyperbolic angle in radian. The parameter can be of double, float or long double datatype.

Return Value:The function returns the hyperbolic tangent of the argument.

Below programs illustrate the above method:

Program 1:

 `// CPP program to demonstrate the ` `// tanh() function ` `#include ` `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``double` `x = 4.1, result; ` ` `  `    ``result = ``tanh``(x); ` `    ``cout << ``"tanh(4.1) = "` `<< result << endl; ` ` `  `    ``// x in Degrees ` `    ``double` `xDegrees = 90; ` `    ``x = xDegrees * 3.14159 / 180; ` ` `  `    ``result = ``tanh``(x); ` `    ``cout << ``"tanh(90 degrees) = "` `<< result << endl; ` ` `  `    ``return` `0; ` `} `

Output:

```tanh(4.1) = 0.999451
tanh(90 degrees) = 0.917152
```

Program 2:

 `// CPP program to demonstrate the ` `// tanh() function ` `#include ` `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``int` `x = -4; ` `    ``double` `result; ` ` `  `    ``result = ``tanh``(x); ` `    ``cout << ``"tanh(-4) = "` `<< result << endl; ` ` `  `    ``// x in Degrees ` `    ``double` `xDegrees = 90; ` `    ``x = xDegrees * 3.14159 / 180; ` ` `  `    ``result = ``tanh``(x); ` `    ``cout << ``"tanh(90 degrees) = "` `<< result << endl; ` ` `  `    ``return` `0; ` `} `

Output:

```tanh(-4) = -0.999329
tanh(90 degrees) = 0.761594
```

Errors and Exceptions: The function returns no matching function for call to error when a string or character is passed as an argument.

Program 3:

 `// CPP program to demonstrate the tanh() ` `// function when a string is passed as argument  ` `#include ` `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``string x = ``"gfg"``; ` `    ``double` `result; ` ` `  `    ``result = ``tanh``(x); ` `    ``cout << ``"tanh(x) = "` `<< result << endl; ` ` `  `    ``return` `0; ` `} `

Output:

```prog.cpp:14:20: error: no matching function for call to 'tanh(std::__cxx11::string&)'
result = tanh(x);
```

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.