當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C++ sinh()用法及代碼示例


sinh()是C++ STL中的內置函數,它返回以弧度給出的角度的雙曲正弦值。

用法:


sinh(data_type x)

參數:該函數接受一個強製性參數x,該參數指定弧度中的雙曲角。該參數可以是double,float或long double數據類型。

返回值:該函數返回參數的雙曲正弦值。如果結果的大小太大而無法用返回類型的值表示,則該函數返回inf。

示例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; 
}
輸出:
sinh(4.1) = 30.1619
sinh(90 degrees) = 2.3013

示例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; 
}
輸出:
sinh(-4) = -27.2899
sinh(90 degrees) = 1.1752

錯誤和異常:當字符串或字符作為參數傳遞時,該函數不返回任何匹配函數來調用錯誤。

以下程序說明了sinh()方法的錯誤和異常:

示例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: error: no matching function for call to 'sinh(std::__cxx11::string&)'
result = sinh(x);

示例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; 
}
輸出:
sinh(3000.0) = inf


相關用法


注:本文由純淨天空篩選整理自pawan_asipu大神的英文原創作品 sinh() function in C++ STL。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。