tmain.cpp - numeric - C++ library with numerical algorithms | |
git clone git://src.adamsgaard.dk/numeric | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
tmain.cpp (1280B) | |
--- | |
1 #include <iostream> | |
2 #include "header.h" | |
3 #include "functions.h" | |
4 #include "integrator.h" | |
5 | |
6 int main(int argc, char* argv[]) | |
7 { | |
8 // Namespace declarations | |
9 using std::cout; | |
10 | |
11 // Calculate machine precision | |
12 Floattype eps_machine = 1.0f; | |
13 while (1.0f + eps_machine != 1.0f) | |
14 eps_machine /= 2.0f; | |
15 | |
16 Floattype a, b, acc, eps; | |
17 | |
18 // Find the integral of function 1 | |
19 a = 0.0f, b = 1.0f; | |
20 acc = 0.001f; eps = acc; | |
21 ncalls = 0; | |
22 Integral F1(func1, a, b, acc, eps); | |
23 F1.show("f(x) = x*x"); | |
24 cout << '\n'; | |
25 | |
26 // Find the integral of function 2 | |
27 a = 1e-8f, b = 1.0f; | |
28 acc = 0.001f; eps = acc; | |
29 ncalls = 0; | |
30 Integral F2(func2, a, b, acc, eps); | |
31 F2.show("f(x) = log(x)/sqrt(x)"); | |
32 cout << "Check: Integral equal to -4:\t"; | |
33 check(fabs(F2.result() + 4.0f) < 0.1f); | |
34 cout << '\n'; | |
35 | |
36 // Find the integral of function 3 | |
37 a = 0.0f, b = 1.0f; | |
38 acc = 1e-8f; eps = acc; | |
39 ncalls = 0; | |
40 Integral F3(func3, a, b, acc, eps); | |
41 F3.show("f(x) = 4*sqrt(1-(1-x)^2)"); | |
42 cout << "Check: Integral equal to pi:\t"; | |
43 check(fabs(F3.result() - M_PI) < 0.01f); | |
44 cout << '\n'; | |
45 | |
46 // Return successfully | |
47 return 0; | |
48 } | |
49 | |
50 void check(const bool statement) | |
51 { | |
52 using std::cout; | |
53 if (statement == true) | |
54 cout << "\t\033[0;32mPassed\033[0m\n"; | |
55 else | |
56 cout << "\t\033[1;31mFail!!\033[0m\n"; | |
57 } |