std:: tanh, std:: tanhf, std:: tanhl
|
ヘッダー
<cmath>
で定義
|
||
| (1) | ||
|
float
tanh
(
float
num
)
;
double
tanh
(
double
num
)
;
|
(C++23まで) | |
|
/*floating-point-type*/
tanh ( /*floating-point-type*/ num ) ; |
(C++23から)
(constexprはC++26から) |
|
|
float
tanhf
(
float
num
)
;
|
(2) |
(C++11から)
(constexprはC++26から) |
|
long
double
tanhl
(
long
double
num
)
;
|
(3) |
(C++11から)
(constexprはC++26から) |
|
SIMDオーバーロード
(C++26から)
|
||
|
ヘッダー
<simd>
で定義
|
||
|
template
<
/*math-floating-point*/
V
>
constexpr
/*deduced-simd-t*/
<
V
>
|
(S) | (C++26から) |
|
追加のオーバーロード
(C++11から)
|
||
|
ヘッダー
<cmath>
で定義
|
||
|
template
<
class
Integer
>
double tanh ( Integer num ) ; |
(A) | (constexprはC++26から) |
std::tanh
のオーバーロードを提供します。
(C++23以降)
|
S)
SIMDオーバーロードは
v_num
に対して要素ごとに
std::tanh
を実行します。
|
(C++26以降) |
|
A)
すべての整数型に対して追加のオーバーロードが提供されており、これらは
double
として扱われます。
|
(C++11以降) |
目次 |
パラメータ
| num | - | 浮動小数点または整数値 |
戻り値
If no errors occur, the hyperbolic tangent of num ( tanh(num) , or|
e
num
-e -num |
|
e
num
+e -num |
アンダーフローによる範囲エラーが発生した場合、正しい結果(丸め後)が返されます。
エラーハンドリング
エラーは、 math_errhandling で指定された通りに報告されます。
IEEE浮動小数点演算(IEC 60559)を実装がサポートしている場合、
- 引数が±0の場合、±0が返されます。
- 引数が±∞の場合、±1が返されます。
- 引数がNaNの場合、NaNが返されます。
注記
POSIXは アンダーフローの場合、 num が変更されずに返されることを規定しており、それがサポートされていない場合、DBL_MIN、FLT_MIN、LDBL_MIN以下の実装定義値が返されます。
追加のオーバーロードは (A) と完全に同一である必要はありません。整数型の引数 num に対して、 std :: tanh ( num ) が std :: tanh ( static_cast < double > ( num ) ) と同じ効果を持つことを保証するのに十分なものであればよいのです。
例
#include <cmath> #include <iostream> #include <random> double get_random_between(double min, double max) { std::random_device rd; std::mt19937 gen(rd()); return std::uniform_real_distribution<>(min, max)(gen); } int main() { const double x = get_random_between(-1.0, 1.0); std::cout << std::showpos << "tanh(+1) = " << std::tanh(+1) << '\n' << "tanh(-1) = " << std::tanh(-1) << '\n' << "tanh(x)*sinh(2*x)-cosh(2*x) = " << std::tanh(x) * std::sinh(2 * x) - std::cosh(2 * x) << '\n' // special values: << "tanh(+0) = " << std::tanh(+0.0) << '\n' << "tanh(-0) = " << std::tanh(-0.0) << '\n'; }
出力:
tanh(+1) = +0.761594 tanh(-1) = -0.761594 tanh(x)*sinh(2*x)-cosh(2*x) = -1 tanh(+0) = +0 tanh(-0) = -0
関連項目
|
(C++11)
(C++11)
|
双曲線正弦を計算する (
sinh(x)
)
(関数) |
|
(C++11)
(C++11)
|
双曲線余弦を計算する (
cosh(x)
)
(関数) |
|
(C++11)
(C++11)
(C++11)
|
逆双曲線正接を計算する (
artanh(x)
)
(関数) |
|
複素数の双曲線正接を計算する (
tanh(z)
)
(関数テンプレート) |
|
|
関数
std::tanh
をvalarrayの各要素に適用する
(関数テンプレート) |
|
|
Cドキュメント
for
tanh
|
|