Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82751829
compute_pi.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Sep 13, 05:56
Size
826 B
Mime Type
text/x-c
Expires
Sun, Sep 15, 05:56 (2 d)
Engine
blob
Format
Raw Data
Handle
20737162
Attached To
R7571 SP4E-TB-TL-FR
compute_pi.cc
View Options
#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
Log In to Comment