Namespaces
Variants

std:: cosh, std:: coshf, std:: coshl

From cppreference.net
Common mathematical functions
Nearest integer floating point operations
(C++11)
(C++11)
(C++11) (C++11) (C++11)
Floating point manipulation functions
(C++11) (C++11)
(C++11)
(C++11)
Classification and comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Types
(C++11)
(C++11)
(C++11)
Macro constants
헤더 파일에 정의됨 <cmath>
(1)
float cosh ( float num ) ;

double cosh ( double num ) ;

long double cosh ( long double num ) ;
(C++23 이전)
/*floating-point-type*/
cosh ( /*floating-point-type*/ num ) ;
(C++23 이후)
(C++26부터 constexpr)
float coshf ( float num ) ;
(2) (C++11 이후)
(C++26부터 constexpr)
long double coshl ( long double num ) ;
(3) (C++11 이후)
(C++26부터 constexpr)
SIMD 오버로드 (C++26 이후)
헤더 파일에 정의됨 <simd>
template < /*math-floating-point*/ V >

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

cosh ( const V & v_num ) ;
(S) (C++26 이후)
추가 오버로드 (C++11 이후)
헤더 파일에 정의됨 <cmath>
template < class Integer >
double cosh ( Integer num ) ;
(A) (C++26부터 constexpr)
1-3) num 의 쌍곡코사인을 계산합니다. 라이브러리는 매개변수 타입으로 모든 cv-unqualified 부동소수점 타입에 대한 std::cosh 오버로드를 제공합니다. (C++23부터)
S) SIMD 오버로드는 v_num 에 대해 요소별(element-wise) std::cosh 연산을 수행합니다.
(정의는 math-floating-point deduced-simd-t 참조)
(C++26부터)
A) 모든 정수 타입에 대해 추가 오버로드가 제공되며, 이들은 double 로 처리됩니다.
(since C++11)

목차

매개변수

num - 부동 소수점 또는 정수 값

반환값

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

오버플로로 인한 범위 오류가 발생하면, +HUGE_VAL , +HUGE_VALF , 또는 +HUGE_VALL 가 반환됩니다.

오류 처리

오류는 math_errhandling 에 명시된 대로 보고됩니다.

구현이 IEEE 부동 소수점 연산(IEC 60559)을 지원하는 경우,

  • 인수가 ±0인 경우, 1이 반환됩니다.
  • 인수가 ±∞인 경우, +∞가 반환됩니다.
  • 인수가 NaN인 경우, NaN이 반환됩니다.

참고 사항

IEEE 호환 타입 double 의 경우, |num| > 710.5 이면 std :: cosh ( num ) 가 오버플로됩니다.

추가 오버로드는 반드시 (A) 와 정확히 동일하게 제공될 필요는 없습니다. 정수 타입의 인수 num 에 대해 std :: cosh ( num ) std :: cosh ( static_cast < double > ( num ) ) 와 동일한 효과를 가지도록 보장하기에 충분하기만 하면 됩니다.

예제

#include <cerrno>
#include <cfenv>
#include <cmath>
#include <cstring>
#include <iostream>
// #pragma STDC FENV_ACCESS ON
int main()
{
    const double x = 42;
    std::cout << "cosh(1) = " << std::cosh(1) << '\n'
              << "cosh(-1) = " << std::cosh(-1) << '\n'
              << "log(sinh(" << x << ")+cosh(" << x << ")) = "
              << std::log(std::sinh(x) + std::cosh(x)) << '\n';
    // 특수 값
    std::cout << "cosh(+0) = " << std::cosh(0.0) << '\n'
              << "cosh(-0) = " << std::cosh(-0.0) << '\n';
    // 오류 처리
    errno=0;
    std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "cosh(710.5) = " << std::cosh(710.5) << '\n';
    if (errno == ERANGE)
        std::cout << "    errno == ERANGE: " << std::strerror(errno) << '\n';
    if (std::fetestexcept(FE_OVERFLOW))
        std::cout << "    FE_OVERFLOW raised\n";
}

가능한 출력:

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

참고 항목

(C++11) (C++11)
쌍곡사인을 계산함 ( sinh(x) )
(함수)
(C++11) (C++11)
쌍곡탄젠트를 계산함 ( tanh(x) )
(함수)
(C++11) (C++11) (C++11)
역쌍곡코사인을 계산함 ( arcosh(x) )
(함수)
복소수의 쌍곡코사인을 계산함 ( cosh(z) )
(함수 템플릿)
함수 std::cosh 를 valarray의 각 요소에 적용함
(함수 템플릿)
C 문서 참조 cosh