Page MenuHomec4science

compute_pi.cc
No OneTemporary

File Metadata

Created
Fri, Sep 13, 05:56

compute_pi.cc

#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include "compute_pi.hh"
// Implement serie converging to pi
// double ComputePi::compute(unsigned int N) {
// float sum = 0;
// for (double k = 1; k < N + 1; k++){
// number_of_operations += 1;
// sum += 1 / (k * k);
// }
// double pi_comp = sqrt(6 * sum);
// return pi_comp;
// }
double ComputePi::compute(unsigned int N) {
for (double k = current_index+1; k < N + 1; k++){
number_of_operations += 1;
current_value += 1 / (k * k);
}
current_index = N;
return sqrt(6 * current_value);
}
// Get analytic prediction of PI
double ComputePi::getAnalyticPrediction() {
return M_PI;
}
// Get name of the implemented serie
std::string ComputePi::getName() {
return "ComputePi";
}

Event Timeline