std::sinh(std::valarray)(3)
hey bestie π welcome to std::sinh(std::valarray)(3) from the C++ Standard Libary manual β yes, that's the manual name, typo and all, and we're keeping the lore. This is the C++ Standard Library's valarray hyperbolic-sine page and it's lowkey a serve π¦β¨
β¨ NAME β¨
std::sinh(std::valarray) - std::sinh(std::valarray) β the name, twice, because why not π
πΈ Synopsis πΈ
Defined in header <valarray>
template< class T >
valarray<T> sinh( const valarray<T>& va );
For each element in va computes hyperbolic sine of the value of the element. That's the whole assignment, no cap π«Ά
π Parameters π
vaβ value array to apply the operation to
π Return value π
Value array containing hyperbolic sine of the values in va. Slay, a whole new array of vibes β¨
π§ Notes π§
okay so the computation uses the unqualified function (sinh) β no std:: prefix in the call, bestie. If such function is not available, std::sinh is used due to argument-dependent lookup. ADL said "I got you" π
The function can be implemented with the return type different from std::valarray. In this case, the replacement type has the following properties:
- All
constmember functions ofstd::valarrayare provided. periodt. std::valarray,std::slice_array,std::gslice_array,std::mask_arrayandstd::indirect_arraycan be constructed from the replacement type.- For every function taking a
const std::valarray<T>&exceptbegin()andend()(since C++11), identical functions taking the replacement types shall be added; - For every function taking two
const std::valarray<T>&arguments, identical functions taking every combination ofconst std::valarray<T>&and replacement types shall be added. - The return type does not add more than two levels of template nesting over the most deeply-nested argument type.
This is the whole replacement-type contract, and it is giving "we have valarray at home" energy but legally ππ
π οΈ Possible implementation π οΈ
template<class T>
valarray<T> sinh(const valarray<T>& va)
{
valarray<T> other = va;
for (T& i : other)
i = sinh(i);
return other; // proxy object may be returned
}
π» Example π»
Run this code, bestie:
// Run this code
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <valarray>
template<typename T>
void show(char const* title, const std::valarray<T>& va)
{
std::cout << title << " : " << std::right;
for (T x : va)
std::cout << std::fixed << x << ' ';
std::cout << '\n';
}
template<typename T>
void sinh_for(std::valarray<T> const& z)
{
// Hyperbolic sine is sinh(z) = (eαΆ» - eβ»αΆ») / 2.
const std::valarray<T> sinh_z{std::sinh(z)};
const std::valarray<T> e_z{std::exp(z)};
const std::valarray<T> e_neg_z{std::exp(-z)};
const std::valarray<T> sinh_def{(e_z - e_neg_z) / 2.0f};
show("n ", z);
show("sinh(n) ", sinh_z);
show("(eβΏ-eβ»βΏ)/2", sinh_def);
std::cout.put('\n');
}
int main()
{
sinh_for(std::valarray<float>{-.2f, -.1f, 0.f, .1f, .2f, INFINITY});
sinh_for(std::valarray<std::complex<double>>{{-.2,-.1}, {.2,.1}});
}
π€ Output π€
n : -0.200000 -0.100000 0.000000 0.100000 0.200000 inf
sinh(n) : -0.201336 -0.100167 0.000000 0.100167 0.201336 inf
(eβΏ-eβ»βΏ)/2 : -0.201336 -0.100167 0.000000 0.100167 0.201336 inf
n : (-0.200000,-0.100000) (0.200000,0.100000)
sinh(n) : (-0.200330,-0.101837) (0.200330,0.101837)
(eβΏ-eβ»βΏ)/2 : (-0.200330,-0.101837) (0.200330,0.101837)
π See also π
cosh(std::valarray)β applies the functionstd::coshto each element ofvalarray(function template)tanh(std::valarray)β applies the functionstd::tanhto each element ofvalarray(function template)sinh,sinhf,sinhlβ computes hyperbolic sine (\({\small\sinh{x}}\)sinh(x)) (function); the see-also row also carries(C++11)and(C++11)markerssinh(std::complex)β computes hyperbolic sine of a complex number (\({\small\sinh{z}}\)sinh(z)) (function template)
π Hidden category π
- Pages with unreviewed LWG DR marker
okay bye bestie π«Ά this page was sourced from http://cppreference.com, version/date 2024.06.10, and yes it's still std::sinh(std::valarray)(3) β mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms