The cosh functions - cosh, coshf, coshl

双曲線余弦 (cosh) を計算します.

cosh

#include <math.h>
double cosh(
    double x
);

cosh 関数は x の双曲線余弦 (cosh) を計算し,結果を double 型で返します.

coshf (C99)

#include <math.h>
float coshf(
    float x
);

coshf 関数は x の双曲線余弦 (cosh) を計算し,結果を float 型で返します.

coshl (C99)

#include <math.h>
long double coshl(
    long double x
);

coshl 関数は x の双曲線余弦 (cosh) を計算し,結果を long double 型で返します.

cosh,coshf,coshl 関数は,x の絶対値が大きすぎる場合,値域エラー (range error) が発生します.

戻り値

  • 双曲線余弦値

数学上の表記

cosh

C言語サンプルプログラム

以下にcosh 関数を使用したサンプルプログラムを示します.

/* header files */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/* main */
int main(void) {
    double x = 2.0;
    double cosh_x01, cosh_x02;

    /* 双曲線余弦を求める */
    cosh_x01 = cosh(x);
    cosh_x02 = ((exp(x) + exp(-x)) / 2.0);

    /* 表示 */
    printf("cosh 関数で求めた値:    %.10f\n", cosh_x01);
    printf("数学的定義から求めた値: %.10f\n", cosh_x02);

    return EXIT_SUCCESS;
}

実行例

サンプルプログラムの実行結果は以下のようになります.

cosh 関数で求めた値:  3.7621956911
数学的定義から求めた値: 3.7621956911