Elements
5.10
A C++ base framework for the Euclid Software.
ElementsExamples
src
lib
PiCalculator.cpp
Go to the documentation of this file.
1
19
#include "
ElementsExamples/PiCalculator.h
"
20
21
namespace
Elements
{
22
namespace
Examples {
23
24
void
PiCalculator::calculate
(
unsigned
int
terms) {
25
26
double
pi
= 0.0;
27
// Leibniz formula for pi
28
double
numerator = -1.0;
29
double
denominator = -1.0;
30
31
for
(
unsigned
int
ii = 0; ii < terms; ++ii) {
32
numerator *= -1;
33
denominator += 2.0;
34
pi
+= numerator / denominator;
35
}
36
37
pi
*= 4.0;
38
39
m_show_result_callback
(
pi
);
40
41
}
42
43
void
PiCalculator::setShowResultCallback
(show_result_callback_type f) {
44
45
m_show_result_callback
= f;
46
47
}
48
49
50
}
// namespace Examples
51
}
// namespace Elements
Elements::Units::pi
constexpr double pi
Definition:
MathConstants.h:33
Elements::Examples::PiCalculator::setShowResultCallback
void setShowResultCallback(show_result_callback_type f)
Definition:
PiCalculator.cpp:43
Elements::Examples::PiCalculator::calculate
void calculate(unsigned int terms)
Definition:
PiCalculator.cpp:24
PiCalculator.h
Elements::Examples::PiCalculator::m_show_result_callback
show_result_callback_type m_show_result_callback
Definition:
PiCalculator.h:41
Elements
Definition:
ClassExample.h:38
Generated by
1.8.18