std::acos(std::valarray)(3)

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

πŸ’– std::acos(std::valarray)(3) πŸ’–

Okay bestie, this page is from the C++ Standard Libary manual β€” yes, that's the manual name exactly as the header spells it, not a typo I made πŸ’….


🌸 NAME 🌸

The name is std::acos(std::valarray), and the one-line summary is also std::acos(std::valarray). It's giving "I said what I said" energy, and honestly? Iconic.

✨ Synopsis ✨

Defined in header <valarray> β€” here's the exact signature block, no cap:

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

For each element in va, it computes the arc cosine of the value of that element. Slay.

πŸŽ€ Parameters πŸŽ€

  • va β€” the value array to apply the operation to. That's the whole parameter list, periodt.

πŸ’œ Return value πŸ’œ

A value array containing the arc cosines of the values in va. Cute, consistent, done.

πŸ¦‹ Notes πŸ¦‹

The unqualified function (acos) is used to perform the computation. If such a function is not available, std::acos is used because of argument-dependent lookup. (iykyk)

The function can be implemented with a return type that is different from std::valarray. In that case, the replacement type has these 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> acos(const valarray<T>& va)
{
    valarray<T> other = va;
    for (T& i : other)
        i = acos(i);

    return other; // proxy object may be returned
}

πŸ“ Example πŸ“

The page says // Run this code, so here's the code, verbatim:

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

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

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

⭐ Output ⭐

180Β° 150Β° 135Β° 120Β° 90Β° 60Β° 45Β° 30Β° 0Β°

πŸ‘‘ See also πŸ‘‘

  • asin(std::valarray) β€” applies the function std::asin 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)
  • cos(std::valarray) β€” applies the function std::cos to each element of valarray (function template)
  • acos
  • acosf β€” computes arc cosine; \({\small\arccos{x}}\)arccos(x); (function)
  • acosl β€” (C++11) (C++11)
  • acos(std::complex) β€” computes arc cosine of a complex number; (C++11); \({\small\arccos{z}}\)arccos(z); (function template)

πŸ’€ Hidden category πŸ’€

  • Pages with unreviewed LWG DR marker

Mwah πŸ’‹ that's the whole page, bestie. Source is http://cppreference.com, dated 2024.06.10, and the footer also says std::acos(std::valarray)(3) β€” so there you go, every crumb preserved. πŸ’–

πŸ“¦ where this page comes from