]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/multiprecision/example/float128_snips.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / multiprecision / example / float128_snips.cpp
CommitLineData
7c673cae
FG
1///////////////////////////////////////////////////////////////
2// Copyright 2013 John Maddock. Distributed under the Boost
3// Software License, Version 1.0. (See accompanying file
92f5a8d4 4// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
7c673cae 5
f67539c2
TL
6// Demonstrations of using Boost.Multiprecision float128 quad type.
7// (Only available using GCC compiler).
8
9// Contains Quickbook markup in comments.
10
7c673cae
FG
11//[float128_eg
12#include <boost/multiprecision/float128.hpp>
13#include <boost/math/special_functions/gamma.hpp>
14#include <iostream>
15
16int main()
17{
f67539c2
TL
18 using namespace boost::multiprecision; // Potential to cause name collisions?
19 // using boost::multiprecision::float128; // is safer.
7c673cae 20
f67539c2
TL
21/*`The type float128 provides operations at 128-bit precision with
22[@https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format#IEEE_754_quadruple-precision_binary_floating-point_format:_binary128 Quadruple-precision floating-point format]
23and have full `std::numeric_limits` support:
24*/
7c673cae 25 float128 b = 2;
f67539c2 26//` There are 15 bits of (biased) binary exponent and 113-bits of significand precision
7c673cae 27 std::cout << std::numeric_limits<float128>::digits << std::endl;
f67539c2 28//` or 33 decimal places:
7c673cae 29 std::cout << std::numeric_limits<float128>::digits10 << std::endl;
f67539c2
TL
30 //` We can use any C++ std library function, so let's show all the at-most 36 potentially significant digits, and any trailing zeros, as well:
31 std::cout.setf(std::ios_base::showpoint); // Include any trailing zeros.
32 std::cout << std::setprecision(std::numeric_limits<float128>::max_digits10)
33 << log(b) << std::endl; // Shows log(2) = 0.693147180559945309417232121458176575
34 //` We can also use any function from Boost.Math, for example, the 'true gamma' function `tgamma`:
7c673cae 35 std::cout << boost::math::tgamma(b) << std::endl;
f67539c2
TL
36 /*` And since we have an extended exponent range, we can generate some really large
37 numbers here (4.02387260077093773543702433923004111e+2564):
38 */
7c673cae 39 std::cout << boost::math::tgamma(float128(1000)) << std::endl;
f67539c2
TL
40 /*` We can declare constants using GCC or Intel's native types, and literals with the Q suffix, and these can be declared `constexpr` if required:
41 */
f67539c2
TL
42 // std::numeric_limits<float128>::max_digits10 = 36
43 constexpr float128 pi = 3.14159265358979323846264338327950288Q;
44 std::cout.precision(std::numeric_limits<float128>::max_digits10);
45 std::cout << "pi = " << pi << std::endl; //pi = 3.14159265358979323846264338327950280
f67539c2 46//] [/float128_eg]
7c673cae
FG
47 return 0;
48}
f67539c2
TL
49
50/*
51//[float128_numeric_limits
52
53GCC 8.1.0
54
55Type name is float128_t:
56Type is g
57std::is_fundamental<> = true
1e59de90
TL
58boost::multiprecision::detail::is_signed<> = true
59boost::multiprecision::detail::is_unsigned<> = false
60boost::multiprecision::detail::is_integral<> = false
61boost::multiprecision::detail::is_arithmetic<> = true
f67539c2
TL
62std::is_const<> = false
63std::is_trivial<> = true
64std::is_standard_layout<> = true
65std::is_pod<> = true
66std::numeric_limits::<>is_exact = false
67std::numeric_limits::<>is bounded = true
68std::numeric_limits::<>is_modulo = false
69std::numeric_limits::<>is_iec559 = true
70std::numeric_limits::<>traps = false
71std::numeric_limits::<>tinyness_before = false
72std::numeric_limits::<>max() = 1.18973149535723176508575932662800702e+4932
73std::numeric_limits::<>min() = 3.36210314311209350626267781732175260e-4932
74std::numeric_limits::<>lowest() = -1.18973149535723176508575932662800702e+4932
75std::numeric_limits::<>min_exponent = -16381
76std::numeric_limits::<>max_exponent = 16384
77std::numeric_limits::<>epsilon() = 1.92592994438723585305597794258492732e-34
78std::numeric_limits::<>radix = 2
79std::numeric_limits::<>digits = 113
80std::numeric_limits::<>digits10 = 33
81std::numeric_limits::<>max_digits10 = 36
82std::numeric_limits::<>has denorm = true
83std::numeric_limits::<>denorm min = 6.47517511943802511092443895822764655e-4966
84std::denorm_loss = false
85limits::has_signaling_NaN == false
86std::numeric_limits::<>quiet_NaN = nan
87std::numeric_limits::<>infinity = inf
88
89//] [/float128_numeric_limits]
90*/
91
7c673cae 92