std::atanh(std::complex)(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::atanh(std::complex) β€” the C++ Standard Library one, bestie

Okay so picture this: it's a (3) manual page, it lives in the C++ Standard Library, and its whole entire personality is std::atanh(std::complex). That's the name, that's the vibe, we move. πŸ¦‹


✨ Synopsis ✨

First things first, she's Defined in header <complex> β€” don't forget to bring her along.

template< class T >                       (since C++11)
complex<T> atanh( const complex<T>& z );

So what does she do? She computes the complex arc hyperbolic tangent of z, and the branch cuts sit outside the interval [βˆ’1; +1] along the real axis. Lowkey iconic behavior tbh. πŸŽ€


🌸 Parameters 🌸

  • z β€” a complex value. that's it, that's the whole parameter list, she's low-maintenance.

πŸ‘‘ Return value πŸ‘‘

If literally no errors happen (a blessed day ✨), you get the complex arc hyperbolic tangent of z back, and it lives in the range of a half-strip that is mathematically unbounded along the real axis and sits in the interval [βˆ’iΟ€/2; +iΟ€/2] along the imaginary axis. Slay.

πŸ’€ Error handling and special values πŸ’€

Errors get reported consistent with math_errhandling. fr fr, that's the system.

If the implementation supports IEEE floating-point arithmetic, here's the whole mood board:

  • std::atanh(std::conj(z)) == std::conj(std::atanh(z))
  • std::atanh(-z) == -std::atanh(z)
  • If z is (+0,+0), the result is (+0,+0)
  • If z is (+0,NaN), the result is (+0,NaN)
  • If z is (+1,+0), the result is (+∞,+0) and FE_DIVBYZERO is raised
  • If z is (x,+∞) (for any finite positive x), the result is (+0,Ο€/2)
  • If z is (x,NaN) (for any finite nonzero x), the result is (NaN,NaN) and FE_INVALID may be raised
  • If z is (+∞,y) (for any finite positive y), the result is (+0,Ο€/2)
  • If z is (+∞,+∞), the result is (+0,Ο€/2)
  • If z is (+∞,NaN), the result is (+0,NaN)
  • If z is (NaN,y) (for any finite y), the result is (NaN,NaN) and FE_INVALID may be raised
  • If z is (NaN,+∞), the result is (Β±0,Ο€/2) (the sign of the real part is unspecified β€” yeah, she's mysterious like that πŸ™ˆ)
  • If z is (NaN,NaN), the result is (NaN,NaN)

🧚 Notes 🧚

Bestie, this is the part where we get a little pedantic and honestly we should. πŸ’…

Even though the C++ standard calls this function "complex arc hyperbolic tangent", the inverse functions of the hyperbolic functions are actually the area functions. Their argument is the area of a hyperbolic sector, not an arc. So the correct name is "complex inverse hyperbolic tangent" and, less common, "complex area hyperbolic tangent". The way that etymology stayed relevant 😭

Inverse hyperbolic tangent is a multivalued function and she requires a branch cut on the complex plane. By convention the branch cut is placed at the line segments (-∞,-1] and [+1,+∞) of the real axis.

The mathematical definition of the principal value of the inverse hyperbolic tangent is:

atanh z = ( ln(1+z) - ln(1-z) ) / 2

And for any z:

atanh(z) = atan(iz) / i

🌈 Example 🌈

// Run this code

#include <complex>
#include <iostream>

int main()
{
    std::cout << std::fixed;
    std::complex<double> z1(2.0, 0.0);
    std::cout << "atanh" << z1 << " = " << std::atanh(z1) << '\n';

    std::complex<double> z2(2.0, -0.0);
    std::cout << "atanh" << z2 << " (the other side of the cut) = "
              << std::atanh(z2) << '\n';

    // for any z, atanh(z) = atanh(iz) / i
    std::complex<double> z3(1.0, 2.0);
    std::complex<double> i(0.0, 1.0);
    std::cout << "atanh" << z3 << " = " << std::atanh(z3) << '\n'
              << "atan" << z3 * i << " / i = " << std::atan(z3 * i) / i
   << '\n';
}

⭐ Output ⭐

atanh(2.000000,0.000000) = (0.549306,1.570796)
atanh(2.000000,-0.000000) (the other side of the cut) =
(0.549306,-1.570796)
atanh(1.000000,2.000000) = (0.173287,1.178097)
atan(-2.000000,1.000000) / i = (0.173287,1.178097)

πŸ’œ See also πŸ’œ

  • asinh(std::complex) β€” computes area hyperbolic sine of a complex number (C++11) β€” arsinh(z) β€” function template
  • acosh(std::complex) β€” computes area hyperbolic cosine of a complex number (C++11) β€” arcosh(z) β€” function template
  • tanh(std::complex) β€” computes hyperbolic tangent of a complex number β€” tanh(z) β€” function template
  • atanh, atanhf, atanhl (C++11) β€” computes the inverse hyperbolic tangent β€” artanh(x) β€” function
  • C documentation for catanh β€” for when you wanna hang out in C land πŸ“

Okay that's the whole page, no gatekeeping, no cap. Now go forth and compute your arc hyperbolic tangents, but like, correctly. 🫢

Sign-off time, bestie: this little masterpiece came from http://cppreference.com, dated 2024.06.10, and it's the std::atanh(std::complex)(3) page. Periodt. πŸ”₯

πŸ“¦ where this page comes from