]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multiprecision/example/mpfi_snips.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / multiprecision / example / mpfi_snips.cpp
1 ///////////////////////////////////////////////////////////////
2 // Copyright 2011 John Maddock. Distributed under the Boost
3 // Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
5
6 //[mpfi_eg
7 #include <boost/multiprecision/mpfi.hpp>
8 #include <boost/math/special_functions/gamma.hpp>
9 #include <iostream>
10
11 int main()
12 {
13 using namespace boost::multiprecision;
14
15 // Operations at variable precision and no numeric_limits support:
16 mpfi_float a = 2;
17 mpfi_float::default_precision(1000);
18 std::cout << mpfi_float::default_precision() << std::endl;
19 std::cout << sqrt(a) << std::endl; // print root-2
20
21 // Operations at fixed precision and full numeric_limits support:
22 mpfi_float_100 b = 2;
23 std::cout << std::numeric_limits<mpfi_float_100>::digits << std::endl;
24 // We can use any C++ std lib function:
25 std::cout << log(b) << std::endl; // print log(2)
26
27 // Access the underlying data:
28 mpfi_t r;
29 mpfi_init(r);
30 mpfi_set(r, b.backend().data());
31
32 // Construct some explicit intervals and perform set operations:
33 mpfi_float_50 i1(1, 2), i2(1.5, 2.5);
34 std::cout << intersect(i1, i2) << std::endl;
35 std::cout << hull(i1, i2) << std::endl;
36 std::cout << overlap(i1, i2) << std::endl;
37 std::cout << subset(i1, i2) << std::endl;
38 mpfi_clear(r);
39 return 0;
40 }
41 //]
42