Skip to content

Instantly share code, notes, and snippets.

@musically-ut
Created December 20, 2011 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musically-ut/1502070 to your computer and use it in GitHub Desktop.
Save musically-ut/1502070 to your computer and use it in GitHub Desktop.
Testing Standard Deviation calculation
int main() {
StdDevCalc c, c2;
StdDevCalcKnuth k, k2;
for(int i = 0; i < 100; i++) {
c.append(i); // Small values
k.append(i);
c2.append((double) i * 3e151); // Very very large values
k2.append((double) i * 3e151);
}
cout << c.get_std_dev() << endl; // 29.0115
cout << k.get_std_dev() << endl; // 29.0115
cout << endl;
cout << c2.get_std_dev() << endl; // inf
cout << k2.get_std_dev() << endl; // 8.70345e+152
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment