-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboost.cpp
64 lines (49 loc) · 1.69 KB
/
boost.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// #include <algorithm>
// #include <iostream>
// #include <iterator>
// #include <boost/lambda/lambda.hpp>
// int main() {
// using namespace boost::lambda;
// typedef std::istream_iterator<int> in;
// std::for_each(
// in(std::cin), in(),
// std::cout << (_1 * 3) << " ");
// }
// #include <iostream>
// #include <string>
// #include <boost/regex.hpp>
// int main() {
// std::string line;
// boost::regex pat("^Subject: (Re: |Aw: )*(.*)");
// while (std::cin) {
// std::getline(std::cin, line);
// boost::smatch matches;
// if (boost::regex_match(line, matches, pat))
// std::cout << matches[2] << std::endl;
// }
// }
#include <iostream>
#include <boost/math/constants/constants.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using boost::multiprecision::cpp_dec_float_50;
using namespace std;
template<typename T>
inline T circle_area(T r) {
// pi is predefined constant having value
using boost::math::constants::pi;
return pi<T>() * r * r;
}
int main() {
float f_rad = 243.0 / 100;
float f_area = circle_area(f_rad);
double d_rad = 243.0 / 100;
double d_area = circle_area(d_rad);
cpp_dec_float_50 rad_mp = 243.0 / 100;
cpp_dec_float_50 area_mp = circle_area(rad_mp);
cout << "Float: " << setprecision(numeric_limits<float>::digits10) << f_area << endl;
// Double area
cout << "Double: " << setprecision(numeric_limits<double>::digits10) << d_area << endl;
// Area by using Boost Multiprecision
cout << "Boost Multiprecision Res: " << setprecision(numeric_limits<cpp_dec_float_50>::digits10) << area_mp << endl;
return 0;
}