std::acos(std::valarray)(3)
π 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
constmember functions ofstd::valarrayare provided. 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.
π 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 functionstd::asinto each element of valarray (function template)atan(std::valarray)β applies the functionstd::atanto each element of valarray (function template)atan2(std::valarray)β applies the functionstd::atan2to a valarray and a value (function template)cos(std::valarray)β applies the functionstd::costo each element of valarray (function template)acosacosfβ 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
- 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