名前空間
変種
操作

std::tanh, std::tanhf, std::tanhl

From cppreference.com
< cpp‎ | numeric‎ | math
 
 
 
 
ヘッダー <cmath> で定義
(1)
float       tanh ( float num );

double      tanh ( double num );

long double tanh ( long double num );
(C++23まで)
/*浮動小数点数型*/
            tanh ( /*浮動小数点型*/ num );
(C++23から)
(C++26 以降 constexpr)
float       tanhf( float num );
(2) (C++11以降)
(C++26 以降 constexpr)
long double tanhl( long double num );
(3) (C++11以降)
(C++26 以降 constexpr)
ヘッダー <simd> で定義
template< /*math-floating-point*/ V >

constexpr /*deduced-simd-t*/<V>

            tanh ( const V& v_num );
(S) (C++26以降)
ヘッダー <cmath> で定義
template< class Integer >
double      tanh ( Integer num );
(A) (C++26 以降 constexpr)
1-3) num の双曲線正接を計算します。ライブラリは、パラメータの型としてすべての cv-unqualified 浮動小数点型に対する std::tanh のオーバーロードを提供します。(since C++23)
S) SIMD オーバーロードは、v_num に対して要素ごとの std::tanh を実行します。
(定義については、math-floating-point および deduced-simd-t を参照してください。)
(C++26以降)
A) すべての整数型に対する追加のオーバーロードが提供されます。これらは double として扱われます。
(C++11以降)

目次

[edit] Parameters

num - 浮動小数点数または整数値

[edit] Return value

エラーが発生しなかった場合、num の双曲線正接(tanh(num)、または
enum
-e-num
enum
+e-num
)が返されます。

アンダーフローによる範囲エラーが発生した場合、正確な結果 (丸め後) が返される。

[edit] Error handling

エラーは math_errhandling で指定された通りに報告される。

実装がIEEE浮動小数点算術 (IEC 60559) をサポートしている場合、

  • 引数が ±0 の場合、±0 が返されます。
  • 引数が ±∞ の場合、±1 が返されます。
  • 引数が NaN の場合、NaN が返されます。

[edit] Notes

POSIX では、アンダーフローの場合、num は変更されずに返され、それがサポートされない場合は、実装定義の値(DBL_MIN、FLT_MIN、および LDBL_MIN 以下の値)が返されると指定されています。

追加のオーバーロードは、(A) とまったく同じように提供される必要はありません。整数型の引数 num に対して、std::tanh(num)std::tanh(static_cast<double>(num)) と同じ効果を持つことを保証するだけで十分です。

[edit] Example

#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

[edit] See also

(C++11)(C++11)
双曲線正弦を計算する (sinh(x))
(関数) [編集]
(C++11)(C++11)
双曲線余弦を計算する (cosh(x))
(関数) [編集]
(C++11)(C++11)(C++11)
逆双曲線正接を計算する (artanh(x))
(関数) [編集]
複素数の双曲線正接 (ハイパボリックタンジェント) を計算する (tanh(z))
(関数テンプレート) [編集]
valarray の各要素に関数 std::tanh を適用します。
(function template) [編集]
English 日本語 中文(简体) 中文(繁體)