Namespaces
Variants
Views
Actions

std::tanh

From cppreference.com
< cpp‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Exponential functions
(C++11)
(C++11)
(C++11)
(C++11)
Power functions
(C++11)
(C++11)
Trigonometric and hyperbolic functions
tanh
(C++11)
(C++11)
(C++11)
Error and gamma functions
(C++11)
(C++11)
(C++11)
(C++11)
Nearest integer floating point operations
(C++11)(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Floating point manipulation functions
(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)
(C++11)
Classification/Comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Macro constants
(C++11)(C++11)(C++11)(C++11)(C++11)
 
Defined in header <cmath>
float       tanh( float arg );
(1)
double      tanh( double arg );
(2)
long double tanh( long double arg );
(3)
double      tanh( Integral arg );
(4) (since C++11)

Computes the hyperbolic tangent of arg

4) A set of overloads or a function template accepting an argument of any integral type. Equivalent to 2) (the argument is cast to double).

Contents

[edit] Parameters

arg - value of a floating-point or Integral type

[edit] Return value

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

If a range error occurs due to underflow, the correct result (after rounding) is returned.

[edit] Error handling

Errors are reported as specified in math_errhandling

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

  • if the argument is ±0, ±0 is returned
  • If the argument is ±∞, ±1 is returned
  • if the argument is NaN, NaN is returned

[edit] Notes

POSIX specifies that in case of underflow, arg is returned unmodified, and if that is not supported, and implementation-defined value no greater than DBL_MIN, FLT_MIN, and LDBL_MIN is returned.

[edit] Examples

#include <iostream>
#include <cmath>
 
int main()
{
    std::cout << "tanh(1) = " << std::tanh(1) << '\n'
              << "tanh(-1) = " << std::tanh(-1) << '\n'
              << "tanh(0.1)*sinh(0.2)-cosh(0.2) = "
              << std::tanh(0.1) * std::sinh(0.2) - std::cosh(0.2) << '\n';
    // special values
    std::cout << "tanh(+0) = " << std::tanh(+0.0) << '\n'
              << "tanh(-0) = " <<  std::tanh(-0.0) << '\n';
}

Output:

tanh(1) = 0.761594
tanh(-1) = -0.761594
tanh(0.1)*sinh(0.2)-cosh(0.2) = -1
tanh(+0) = 0
tanh(-0) = -0

[edit] See also

computes hyperbolic sine (sh(x))
(function) [edit]
computes hyperbolic cosine (ch(x))
(function) [edit]
(C++11)
computes the inverse hyperbolic tangent (artanh(x))
(function) [edit]
computes hyperbolic tangent of a complex number
(function template) [edit]
applies the function std::tanh to each element of valarray
(function template) [edit]