tanh() function in C++ STL

C++ STL Function : tanh()

The tanh() function uses a mathematical formula to calculate the hyperbolic tangent of a number. This formula involves the use of exponential functions and involves the ratio of the sides of a right triangle in a hyperbolic coordinate system.In this section, we will discuss about library function tanh() in STL which is used in C++.The Standard Template Library(STL) is a set of complete data structures and functions which can be used in C++. 

 

tanh() function in c++ stl

Library Function tanh() in C++

In C++ programming language, the tanh function is included in standard template library.

The range of input argument which is passed to floor function is not limited here as it can be any value such as float or long double also.

Declaration of tanh function

tanh(data_type x)

Parameters of tanh function

The tanh function accepts a single input argument  which is the hyperbolic angle and can be a double/float or long double value.

Parameter           Description
Hyperbolic angle          This value of the parameter can be of double / float or long double type.

Return value of tanh function

The tanh function returns the hyperbolic tangent value of the argument passed.

ParameterReturn Value
Hyperbolic tangent of the argument passedIt returns the value in double / float or long double type.

Implementation of STL Function tanh() in C++

Example 1:

The following code shows the use of tanh function.

Run

#include<bits/stdc++.h> 
using namespace std;  
int main()
{
    double x = 4.1, result;  
    result = tanh(x);
    cout << "tanh(4.1) = " << result << endl;
    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

Example 2:

Run

#include<bits/stdc++.h> 
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);

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription