]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/big_seventh.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / example / big_seventh.cpp
1
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 // Copyright Paul A. Bristow 2012.
8 // Copyright Christopher Kormanyos 2012.
9
10 // This file is written to be included from a Quickbook .qbk document.
11 // It can be compiled by the C++ compiler, and run. Any output can
12 // also be added here as comment or included or pasted in elsewhere.
13 // Caution: this file contains Quickbook markup as well as code
14 // and comments: don't change any of the special comment markups!
15
16 #ifdef _MSC_VER
17 # pragma warning (disable : 4512) // assignment operator could not be generated.
18 # pragma warning (disable : 4996)
19 #endif
20
21 //[big_seventh_example_1
22
23 /*`[h5 Using Boost.Multiprecision `cpp_float` for numerical calculations with high precision.]
24
25 The Boost.Multiprecision library can be used for computations requiring precision
26 exceeding that of standard built-in types such as float, double
27 and long double. For extended-precision calculations, Boost.Multiprecision
28 supplies a template data type called cpp_dec_float. The number of decimal
29 digits of precision is fixed at compile-time via template parameter.
30
31 To use these floating-point types and constants, we need some includes:
32
33 */
34
35 #include <boost/math/constants/constants.hpp>
36
37 #include <boost/multiprecision/cpp_dec_float.hpp>
38 // using boost::multiprecision::cpp_dec_float
39
40 #include <iostream>
41 #include <limits>
42
43 //` So now we can demonstrate with some trivial calculations:
44
45 int main()
46 {
47 /*`Using `typedef cpp_dec_float_50` hides the complexity of multiprecision to allow us
48 to define variables with 50 decimal digit precision just like built-in `double`.
49 */
50 using boost::multiprecision::cpp_dec_float_50;
51
52 cpp_dec_float_50 seventh = cpp_dec_float_50(1) / 7;
53
54 /*`By default, output would only show the standard 6 decimal digits,
55 so set precision to show all 50 significant digits.
56 */
57 std::cout.precision(std::numeric_limits<cpp_dec_float_50>::digits10);
58 std::cout << seventh << std::endl;
59 /*`which outputs:
60
61 0.14285714285714285714285714285714285714285714285714
62
63 We can also use constants, guaranteed to be initialized with the very last bit of precision.
64 */
65
66 cpp_dec_float_50 circumference = boost::math::constants::pi<cpp_dec_float_50>() * 2 * seventh;
67
68 std::cout << circumference << std::endl;
69
70 /*`which outputs
71
72 0.89759790102565521098932668093700082405633411410717
73 */
74 //] [/big_seventh_example_1]
75
76 return 0;
77 } // int main()
78
79
80 /*
81 //[big_seventh_example_output
82
83 0.14285714285714285714285714285714285714285714285714
84 0.89759790102565521098932668093700082405633411410717
85
86 //]
87
88 */
89