std::sinh,s...f,std::sinhl(3)

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

πŸŽ€ std::sinh, std::sinhf, std::sinhl πŸ’…

okay bestie, welcome to the C++ Standard Library page for the hyperbolic sine crew β€” that's std::sinh, std::sinhf, and std::sinhl, no cap. They live in <cmath> and they're literally serving math realness. πŸ¦‹


✨ NAME ✨

std::sinh, std::sinhf, std::sinhl β€” yeah, the name section is just the homies listing themselves again. iconic behavior honestly. πŸ‘‘


🌸 SYNOPSIS 🌸

First things first, these bad girls are defined in header <cmath>. periodt. πŸ’–

float       sinh ( float num );

double      sinh ( double num );                            (until C++23)

long double sinh ( long double num );
/* floating-point-type */                                   (since C++23)
                sinh ( /* floating-point-type */ num );
(constexpr since C++26)
float       sinhf( float num );                     (1) (2) (since C++11)
                                                                (constexpr
since C++26)
long double sinhl( long double num );                   (3) (since C++11)
                                                                (constexpr
since C++26)
Additional overloads (since C++11)
Defined in header <cmath>
template< class Integer >                               (A)
(constexpr since C++26)
double      sinh ( Integer num );

So let's break the lore down for you, because there's a lot going on and it's all slay:

  • 1-3) Computes the hyperbolic sine of num. that's the whole job bestie. πŸ’…
  • Since C++23, the library provides overloads of std::sinh for all cv-unqualified floating-point types as the type of the parameter. yes, all of them. she's flexible like that. ✨
  • A) Additional overloads are provided for all integer types (since C++11), and those get treated as double. so your int walks in and gets the double glow-up. 🧚

πŸ“ Parameters πŸ“

  • num β€” a floating-point or integer value. that's it, that's the whole vibe check. πŸ’œ

πŸ”₯ Return value πŸ”₯

If no errors occur, you get the hyperbolic sine of num (sinh(num), or:

 enum
-e-num
 2

) returned to you. and yes that formula is giving what it needs to give. 😭

If a range error due to overflow occurs, you get ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL returned. so like, infinity said hi. 🌈

If a range error occurs due to underflow, the correct result (after rounding) is returned. tiny but valid. we respect her. πŸŽ€


πŸ’€ Error handling πŸ’€

Errors are reported as specified in math_errhandling. (go read that one too, iykyk.)

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

  • if the argument is Β±0 or ±∞, it is returned unmodified. she returns exactly what she got. no notes. πŸ‘‘
  • if the argument is NaN, NaN is returned. fair enough honestly. πŸ™ˆ

🫢 Notes 🫢

POSIX specifies that in case of underflow, num is returned unmodified, and if that is not supported, an implementation-defined value no greater than DBL_MIN, FLT_MIN, and LDBL_MIN is returned. so like, don't count on the exact tiny number, bestie. πŸ’–

Also β€” and this is the important disclaimer β€” the additional overloads are not required to be provided exactly as (A). They only need to be sufficient to ensure that for their argument num of integer type, std::sinh(num) has the same effect as std::sinh(static_cast<double>(num)). so the behavior is the contract, the implementation is just vibes. ✨


⭐ Example ⭐

run this code, it's literally so fun:

#include <cerrno>
#include <cfenv>
#include <cmath>
#include <cstring>
#include <iostream>
// #pragma STDC FENV_ACCESS ON

int main()
{
    const double x = 42;

    std::cout << "sinh(1) = " << std::sinh(1) << '\n'
              << "sinh(-1) = " << std::sinh(-1) << '\n'
              << "log(sinh(" << x << ")+cosh(" << x << ")) = "
              << std::log(std::sinh(x) + std::cosh(x)) << '\n';

    // special values
    std::cout << "sinh(+0) = " << std::sinh(0.0) << '\n'
              << "sinh(-0) = " << std::sinh(-0.0) << '\n';

    // error handling
    errno = 0;
    std::feclearexcept(FE_ALL_EXCEPT);

    std::cout << "sinh(710.5) = " << std::sinh(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";
}

🌈 Output 🌈

This is what she prints, bestie, look at that overflow pop off:

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

πŸ¦‹ See also πŸ¦‹

  • cosh, coshf, coshl (C++11) β€” computes hyperbolic cosine (cosh(x)) (function)
  • tanh, tanhf, tanhl (C++11) β€” computes hyperbolic tangent (tanh(x)) (function)
  • asinh, asinhf, asinhl (C++11) β€” computes the inverse hyperbolic sine (arsinh(x)) (function)
  • sinh(std::complex) β€” computes hyperbolic sine of a complex number (sinh(z)) (function template)
  • sinh(std::valarray) β€” applies the function std::sinh to each element of valarray (function template)
  • C documentation for sinh

ok that's the whole page bestie, go forth and compute your hyperbolic sines πŸ’…βœ¨

and finally, the cute little sign-off: this was served up fresh from http://cppreference.com, dated 2024.06.10, and it's the std::sinh,s...f,std::sinhl(3) page. love her, bookmark her, hydrate. πŸŽ€πŸ’–πŸ«Ά

πŸ“¦ where this page comes from