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
Definiert im Header <cmath>
(1)
float tanh ( float num ) ;

double tanh ( double num ) ;

long double tanh ( long double num ) ;
(bis C++23)
/*floating-point-type*/
tanh ( /*floating-point-type*/ num ) ;
(seit C++23)
(constexpr seit C++26)
float tanhf ( float num ) ;
(2) (seit C++11)
(constexpr seit C++26)
long double tanhl ( long double num ) ;
(3) (seit C++11)
(constexpr seit C++26)
SIMD-Überladung (seit C++26)
Definiert im Header <simd>
template < /*math-floating-point*/ V >

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

tanh ( const V & v_num ) ;
(S) (seit C++26)
Definiert im Header <cmath>
template < class Integer >
double tanh ( Integer num ) ;
(A) (constexpr seit C++26)
1-3) Berechnet den hyperbolischen Tangens von num . Die Bibliothek bietet Überladungen von std::tanh für alle cv-unqualifizierten Gleitkommatypen als Typ des Parameters an. (since C++23)
S) Die SIMD-Überladung führt eine elementweise std::tanh -Operation auf v_num durch.
(Siehe math-floating-point und deduced-simd-t für deren Definitionen.)
(seit C++26)
A) Zusätzliche Überladungen werden für alle Ganzzahltypen bereitgestellt, die als double behandelt werden.
(since C++11)

Inhaltsverzeichnis

Parameter

num - Fließkomma- oder Ganzzahlwert

Rückgabewert

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

Wenn ein Bereichsfehler aufgrund von Unterlauf auftritt, wird das korrekte Ergebnis (nach Rundung) zurückgegeben.

Fehlerbehandlung

Fehler werden gemeldet, wie in math_errhandling spezifiziert.

Wenn die Implementierung IEEE-Gleitkommaarithmetik (IEC 60559) unterstützt,

  • wenn das Argument ±0 ist, wird ±0 zurückgegeben.
  • wenn das Argument ±∞ ist, wird ±1 zurückgegeben.
  • wenn das Argument NaN ist, wird NaN zurückgegeben.

Hinweise

POSIX spezifiziert dass im Fall eines Unterlaufs, num unverändert zurückgegeben wird, und falls dies nicht unterstützt wird, ein implementierungsdefinierter Wert nicht größer als DBL_MIN, FLT_MIN und LDBL_MIN zurückgegeben wird.

Die zusätzlichen Überladungen müssen nicht exakt wie (A) bereitgestellt werden. Sie müssen lediglich sicherstellen, dass für ihr Argument num vom Ganzzahltyp, std :: tanh ( num ) die gleiche Wirkung hat wie std :: tanh ( static_cast < double > ( num ) ) .

Beispiel

#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'
              // special values:
              << "tanh(+0) = " << std::tanh(+0.0) << '\n'
              << "tanh(-0) = " << std::tanh(-0.0) << '\n';
}

Ausgabe:

tanh(+1) = +0.761594
tanh(-1) = -0.761594
tanh(x)*sinh(2*x)-cosh(2*x) = -1
tanh(+0) = +0
tanh(-0) = -0

Siehe auch

(C++11) (C++11)
berechnet den hyperbolischen Sinus ( sinh(x) )
(Funktion)
(C++11) (C++11)
berechnet den hyperbolischen Kosinus ( cosh(x) )
(Funktion)
(C++11) (C++11) (C++11)
berechnet den Areatangens Hyperbolicus ( artanh(x) )
(Funktion)
berechnet den hyperbolischen Tangens einer komplexen Zahl ( tanh(z) )
(Funktions-Template)
wendet die Funktion std::tanh auf jedes Element des valarray an
(Funktions-Template)