Функция sinh () в C ++ STL

Опубликовано: 18 Февраля, 2022

Sinh () - это встроенная функция в C ++ STL, которая возвращает гиперболический синус угла, заданного в радианах.

Синтаксис:

sinh (тип_данных x)

Параметр: функция принимает один обязательный параметр x, который указывает гиперболический угол в радианах. Параметр может иметь тип данных double, float или long double.

Возвращаемое значение: функция возвращает гиперболический синус аргумента. Если величина результата слишком велика для представления значением возвращаемого типа, функция возвращает inf .

Program 1:

// C++ program to demonstrate the
// sinh() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    double x = 4.1;
  
    double result = sinh(x);
    cout << "sinh(4.1) = " << result << endl;
  
    // x in Degrees
    double xDegrees = 90;
    x = xDegrees * 3.14159 / 180;
  
    result = sinh(x);
    cout << "sinh(90 degrees) = " << result << endl;
  
    return 0;
}
Output:
sinh(4.1) = 30.1619
sinh(90 degrees) = 2.3013

Program 2:

// C++ program to demonstrate the
// sinh() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    int x = -4;
  
    double result = sinh(x);
    cout << "sinh(-4) = " << result << endl;
  
    // x in Degrees
    double xDegrees = 90;
    // convert to radians
    x = xDegrees * 3.14159 / 180;
  
    result = sinh(x);
    cout << "sinh(90 degrees) = " << result << endl;
  
    return 0;
}
Output:
sinh(-4) = -27.2899
sinh(90 degrees) = 1.1752

Ошибки и исключения: функция не возвращает соответствующую функцию для вызова ошибки, когда в качестве аргумента передается строка или символ.

Below programs illustrate the errors and exceptions of sinh() method:

Program 3:
// C++ program to demonstrate the 
// sinh() function when a string is passed
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    string x = "gfg";
    double result;
  
    result = sinh(x);
    cout << "sinh(x) = " << result << endl;
  
    return 0;
}

Выход:

prog.cpp: 14: 20: ошибка: нет соответствующей функции для вызова 'sinh (std :: __ cxx11 :: string &)'
результат = sinh (x);

Program 4:

// C++ program to demonstrate the sinh()
// function When argument is too large
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    double x = 3000.0; 
  
    double result = sinh(x);
    cout << "sinh(x) = " << result << endl;
  
    return 0;
}
Output:
sinh(3000.0) = inf