sinh() function in C++/python
Last Updated :
30 Jun, 2023
The sinh() is an inbuilt function in C++/python which returns the hyperbolic sine of an angle given in radians. Syntax :
sinh(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 sine of the argument. If the magnitude of the result is too large to be represented by a value of the return type, the function returns inf in c++ and overflow python.
Program 1:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
double x = 4.1;
double result = sinh (x);
cout << "sinh(4.1) = " << result << endl;
double xDegrees = 90;
x = xDegrees * 3.14159 / 180;
result = sinh (x);
cout << "sinh(90 degrees) = " << result << endl;
return 0;
}
|
Python
import math
x = 4.1
result = math.sinh(x)
print ( "sinh(4.1) =" , result)
x_degrees = 90
x = x_degrees * math.pi / 180
result = math.sinh(x)
print ( "sinh(90 degrees) =" , result)
|
Output
sinh(4.1) = 30.1619
sinh(90 degrees) = 2.3013
Time Complexity: O(1)
Space Complexity: O(1)
Program 2:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x = -4;
double result = sinh (x);
cout << "sinh(-4) = " << result << endl;
double xDegrees = 90;
x = xDegrees * 3.14159 / 180;
result = sinh (x);
cout << "sinh(90 degrees) = " << result << endl;
return 0;
}
|
Python
import math
x = - 4
result = math.sinh(x)
print ( "sinh(-4) = " , result)
xDegrees = 90
x = xDegrees * 3.14159 / 180
result = math.sinh(x)
print ( "sinh(90 degrees) = " , result)
|
Output
sinh(-4) = -27.2899
sinh(90 degrees) = 1.1752
Time Complexity: O(1)
Space Complexity: O(1)
Errors and Exceptions: The function returns no matching function for call to error when a string or character is passed as an argument.
Below programs illustrate the errors and exceptions of sinh() method:
Program 3:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
string x = "gfg" ;
double result;
result = sinh (x);
cout << "sinh(x) = " << result << endl;
return 0;
}
|
Python
import math
x = "gfg"
result = math.sinh(x)
print ( "sinh(x) =" , result)
|
Output:
prog.cpp:14:20: error: no matching function for call to 'sinh(std::__cxx11::string&)'
result = sinh(x);
Program 4:
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
double x = 3000.0;
double result = sinh (x);
cout << "sinh(x) = " << result << endl;
return 0;
}
|
Python
import math
x = 3000.0
result = math.sinh(x)
print ( "sinh(x) = " , result)
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...