]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multiprecision/example/float128_snips.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / multiprecision / example / float128_snips.cpp
1 ///////////////////////////////////////////////////////////////
2 // Copyright 2013 John Maddock. Distributed under the Boost
3 // Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
5
6 //[float128_eg
7 #include <boost/multiprecision/float128.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 128-bit precision and full numeric_limits support:
16 float128 b = 2;
17 // There are 113-bits of precision:
18 std::cout << std::numeric_limits<float128>::digits << std::endl;
19 // Or 34 decimal places:
20 std::cout << std::numeric_limits<float128>::digits10 << std::endl;
21 // We can use any C++ std lib function, lets print all the digits as well:
22 std::cout << std::setprecision(std::numeric_limits<float128>::max_digits10)
23 << log(b) << std::endl; // print log(2) = 0.693147180559945309417232121458176575
24 // We can also use any function from Boost.Math:
25 std::cout << boost::math::tgamma(b) << std::endl;
26 // And since we have an extended exponent range we can generate some really large
27 // numbers here (4.02387260077093773543702433923004111e+2564):
28 std::cout << boost::math::tgamma(float128(1000)) << std::endl;
29 //
30 // We can declare constants using GCC or Intel's native types, and the Q suffix,
31 // these can be declared constexpr if required:
32 /*<-*/
33 #ifndef BOOST_NO_CXX11_CONSTEXPR
34 /*->*/
35 constexpr float128 pi = 3.1415926535897932384626433832795028841971693993751058Q;
36 /*<-*/
37 #endif
38 /*->*/
39 return 0;
40 }
41 //]
42