Namespaces
Variants

cosh, coshf, coshl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
ヘッダーで定義 <math.h>
float coshf ( float arg ) ;
(1) (C99以降)
double cosh ( double arg ) ;
(2)
long double coshl ( long double arg ) ;
(3) (C99以降)
ヘッダーで定義 <tgmath.h>
#define cosh( arg )
(4) (C99以降)
1-3) arg の双曲線余弦を計算します。
4) 型総称マクロ: 引数の型が long double の場合、 coshl が呼び出される。それ以外の場合、引数が整数型または double 型の場合、 cosh が呼び出される。それ以外の場合、 coshf が呼び出される。引数が複素数の場合、マクロは対応する複素数関数( ccoshf ccosh ccoshl )を呼び出す。

目次

パラメータ

arg - 双曲角を表す浮動小数点値

戻り値

If no errors occur, the hyperbolic cosine of arg ( cosh(arg) , or
e arg
+e -arg
2
) is returned.

オーバーフローによる範囲エラーが発生した場合、 +HUGE_VAL +HUGE_VALF または +HUGE_VALL が返されます。

エラーハンドリング

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

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

  • 引数が±0の場合、1が返される
  • 引数が±∞の場合、+∞が返される
  • 引数がNaNの場合、NaNが返される

注記

IEEE互換の型 double の場合、 |arg| > 710.5 のとき、 cosh(arg) はオーバーフローします。

#include <errno.h>
#include <fenv.h>
#include <math.h>
#include <stdio.h>
// #pragma STDC FENV_ACCESS ON
int main(void)
{
    printf("cosh(1) = %f\ncosh(-1)= %f\n", cosh(1), cosh(-1));
    printf("log(sinh(1) + cosh(1))=%f\n", log(sinh(1) + cosh(1)));
    // special values
    printf("cosh(+0) = %f\ncosh(-0) = %f\n", cosh(0.0), cosh(-0.0));
    // error handling
    errno = 0;
    feclearexcept(FE_ALL_EXCEPT);
    printf("cosh(710.5) = %f\n", cosh(710.5));
    if (errno == ERANGE)
        perror("    errno == ERANGE");
    if (fetestexcept(FE_OVERFLOW))
        puts("    FE_OVERFLOW raised");
}

出力例:

cosh(1) = 1.543081
cosh(-1)= 1.543081
log(sinh(1) + cosh(1))=1.000000
cosh(+0) = 1.000000
cosh(-0) = 1.000000
cosh(710.5) = inf
    errno == ERANGE: Numerical result out of range
    FE_OVERFLOW raised

参考文献

  • C23規格 (ISO/IEC 9899:2024):
  • 7.12.5.4 cosh関数群 (p: TBD)
  • 7.25 総称数学 <tgmath.h> (p: TBD)
  • F.10.2.4 cosh関数群 (p: TBD)
  • C17規格 (ISO/IEC 9899:2018):
  • 7.12.5.4 cosh関数群 (p: 176)
  • 7.25 総称数学 <tgmath.h> (p: 272-273)
  • F.10.2.4 cosh関数群 (p: 379)
  • C11規格 (ISO/IEC 9899:2011):
  • 7.12.5.4 cosh関数 (p: 241)
  • 7.25 総称数学 <tgmath.h> (p: 373-375)
  • F.10.2.4 cosh関数 (p: 520)
  • C99規格 (ISO/IEC 9899:1999):
  • 7.12.5.4 cosh関数 (p: 222)
  • 7.22 総称数学 <tgmath.h> (p: 335-337)
  • F.9.2.4 cosh関数 (p: 457)
  • C89/C90標準 (ISO/IEC 9899:1990):
  • 4.5.3.1 cosh関数

関連項目

(C99) (C99)
双曲線正弦を計算する ( sinh(x) )
(関数)
(C99) (C99)
双曲線正接を計算する ( tanh(x) )
(関数)
(C99) (C99) (C99)
逆双曲線余弦を計算する ( arcosh(x) )
(関数)
(C99) (C99) (C99)
複素双曲線余弦を計算する
(関数)