std::asin(std::valarray)(3)

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

πŸ’– NAME πŸ’–

This is the manual page for std::asin(std::valarray) β€” that’s std::asin(std::valarray)(3) in the manual, section 3 β€” from the C++ Standard Libary manual. Yes bestie, the title is literally std::asin(std::valarray) and this whole page is its moment πŸ’…βœ¨.


🌸 Synopsis 🌸

Defined in header <valarray>
template< class T >
valarray<T> asin( const valarray<T>& va );

For each element in va computes arc sine of the value of the element. It’s giving β€œelement-by-element arc sine” energy, no cap πŸ¦‹.

πŸŽ€ Parameters πŸŽ€

  • va β€” value array to apply the operation to. That’s the whole parameter list, bestie β€” just va carrying the array vibes 🫢.

🌈 Return value 🌈

A value array containing arc sines of the values in va. Slay, it gives you back a whole array of results, not just one number πŸ’–.

πŸ¦‹ Notes πŸ¦‹

Okay so the tea: an unqualified function (asin) is used to perform the computation. If such function is not available, std::asin is used due to argument-dependent lookup. ADL doing its little main-character thing ✨.

The function can be implemented with the return type different from std::valarray. In this case, the replacement type has the following properties:

  • All const member functions of std::valarray are provided.
  • std::valarray, std::slice_array, std::gslice_array, std::mask_array and std::indirect_array can be constructed from the replacement type.
  • For every function taking a const std::valarray<T>& except begin() and end() (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 of const 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.

🧚 Possible implementation 🧚

template<class T>
valarray<T> asin(const valarray<T>& va)
{
    valarray<T> other = va;
    for (T& i : other)
        i = asin(i);

    return other; // proxy object may be returned
}

πŸ“ Example πŸ“

The page says // Run this code right before the snippet:

#include <cmath>
#include <iostream>
#include <numbers>
#include <valarray>

int main()
{
    // take common y-values from unit circle
    const double s22 = std::sqrt(2.0) / 2.0;
    const double s32 = std::sqrt(3.0) / 2.0;
    const std::valarray<double> v1 =
        {-1.0, -s32, -s22, -0.5,  0.0,  0.5, s22,  s32,  1.0};

    // fill with results of radians to degrees conversion
    const std::valarray<double> v2 =
        std::asin(v1) * 180.0 / std::numbers::pi;

    for (std::cout << std::showpos; double n : v2)
        std::cout << n << "Β° ";
    std::cout << '\n';
}

⭐ Output ⭐

-90Β° -60Β° -45Β° -30Β° +0Β° +30Β° +45Β° +60Β° +90Β°

πŸ‘‘ See also πŸ‘‘

  • acos(std::valarray) β€” applies the function std::acos to each element of valarray (function template).
  • atan(std::valarray) β€” applies the function std::atan to each element of valarray (function template).
  • atan2(std::valarray) β€” applies the function std::atan2 to a valarray and a value (function template).
  • sin(std::valarray) β€” applies the function std::sin to each element of valarray (function template).
  • asin β€” computes arc sine (arcsin(x)) (function).
  • asinf β€” computes arc sine (arcsin(x)) (function).
  • asinl β€” computes arc sine (arcsin(x)) (function); (C++11); (C++11).
  • asin(std::complex) β€” computes arc sine of a complex number (arcsin(z)) (function template) (C++11).

πŸ™ˆ Hidden category πŸ™ˆ

  • Pages with unreviewed LWG DR marker

Source/version/date shoutout, bestie: this page is from http://cppreference.com, version/date 2024.06.10, and the page itself is std::asin(std::valarray)(3) β€” bye, love u, go compute some arc sines πŸ’œπŸ«Άβœ¨

πŸ“¦ where this page comes from