Namespaces
Variants

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

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 tanh ( float num ) ;

double tanh ( double num ) ;

long double tanh ( long double num ) ;
(C++23 이전)
/*floating-point-type*/
tanh ( /*floating-point-type*/ 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 오버로드 (C++26 이후)
헤더 파일에 정의됨 <simd>
template < /*math-floating-point*/ V >

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

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

목차

매개변수

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

반환값

If no errors occur, the hyperbolic tangent of num ( tanh(num) , or
e num
-e -num
e num
+e -num
) is returned.

언더플로우로 인해 범위 오류가 발생하는 경우, 올바른 결과(반올림 후)가 반환됩니다.

오류 처리

오류는 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'
              // 특수 값:
              << "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