I have a vector where are 2 values 1.18973e+4932, 1.18973e+4932
vector<long double> v;
In my coursework, I need to find mean and variance of all values in the vector.
long double mean() const {
long double sum = 0;
for (unsigned int i = 0 ; i < len ; i ++)
sum += v[i];
return sum/len;
}
Here I try to find variance
long double variance() const {
long double m = mean();
long double sum = 0;
for (unsigned int i = 0 ; i < len ; i ++)
sum += (v[i] - m) * (v[i] - m);
return sum/len;
}
But I am getting inf as result with 1.18973e+4932 values