|
|
|
|
|
by jeorgun
4459 days ago
|
|
It's even a poor example of C++. Using valarray, you end up with basically the same thing as your above examples: #include <valarray>
#include <iostream>
double standard_dev(const std::valarray<double> &vals)
{
return sqrt(pow(vals - (vals.sum() / vals.size()), 2).sum() / vals.size());
}
int main()
{
std::cout << standard_dev({2, 4, 4, 4, 5, 5, 7, 8}) << '\n';
}
…and none of those are really much less readable than the math version. All in all, that "example" clearly wasn't made in good faith, and left a bad taste in my mouth. |
|