std::log10(std::valarray)(3)
π NAME π
ok so bestie, this page is literally about std::log10(std::valarray) β that's the whole name, no cap. It lives in the C++ Standard Library (I know, fancy), and it's the std::log10 overload that takes a std::valarray. Iconic behavior only π
β¨ Synopsis β¨
First things first, it's defined in header <valarray> π
template< class T >
valarray<T> log10( const valarray<T>& va );
So what does it do? For each element in va, it computes the common (base 10) logarithm of the value of the element. Every single element, one by one, no skipping. Periodt. π«Ά
πΈ Parameters πΈ
vaβ the value array you're applying the operation to. That's it, that's the whole parameter list, she's low maintenance π
π¦ Return value π¦
A value array containing the common logarithms of the values in va. So you hand her a valarray of numbers, she hands you back a valarray of their base-10 logs. Trading cards, basically. β¨
π Notes π
ok this part is the real iykyk section so pay attention bestie π
An unqualified function (log10) is used to perform the computation. But if such a function isn't available, std::log10 gets used instead β and that's all thanks to argument-dependent lookup. Cute, right? π
Also, the function can be implemented with a return type different from std::valarray. In that case, the replacement type has the following properties (this is the fine print, but it's important fine print, fr fr):
- 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. β
That's five properties, and I listed all five, because I would never do you dirty like that π
π§ Possible implementation π§
Here's how she might be built under the hood β copy-paste energy, but make it β¨algorithmicβ¨:
template<class T>
valarray<T> log10(const valarray<T>& va)
{
valarray<T> other = va;
for (T& i : other)
i = log10(i);
return other; // proxy object may be returned
}
Note that little comment at the end β // proxy object may be returned β she's mysterious like that. π
π₯ Example π₯
The page says // Run this code, and honestly? You should. Here it is in full:
#include <cmath>
#include <iomanip>
#include <iostream>
#include <valarray>
void show(char const* title, const std::valarray<float>& va)
{
std::cout << title << " : " << std::right;
for (float x : va)
std::cout << std::setw(6) << x;
std::cout << '\n';
}
int main()
{
const std::valarray<float> n{-2.f, -1.f, 0.f, 1.f, 2.f, 3.f, INFINITY};
const std::valarray<float> pow10{std::pow(10.f, n)};
const std::valarray<float> log10_pow10{std::log10(pow10)};
show("n ", n);
show("10βΏ ", pow10);
show("lg(10βΏ)", log10_pow10);
}
β Output β
n : -2 -1 0 1 2 3 inf
10βΏ : 0.01 0.1 1 10 100 1000 inf
lg(10βΏ) : -2 -1 0 1 2 3 inf
Look at that symmetry π log base 10 and 10-to-the-power literally undoing each other, it's giving soulmate behavior π
π See also π
log(std::valarray)β applies the functionstd::logto each element of valarray (function template)log10,log10f,log10l(C++11), (C++11) β computes common (base 10) logarithm ((\log_{10}{x}), aka log[10](x)) (function)log10(std::complex)β complex common logarithm with the branch cuts along the negative real axis (function template)
Three whole entries, all present and accounted for, because I don't gatekeep π«Ά
π Hidden category π
- Pages with unreviewed LWG DR marker
(She's a little shy, that's why she's hidden πΈ)
ok that's the whole page bestie!! source/version is cppreference.com, 2024.06.10, and the page is std::log10(std::valarray)(3) β go forth and log your valarrays, you absolute main character ππ
β¨
π¦ 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