]>
Commit | Line | Data |
---|---|---|
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 | ||
16 | int 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] | |
23 | and 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 | ||
53 | GCC 8.1.0 | |
54 | ||
55 | Type name is float128_t: | |
56 | Type is g | |
57 | std::is_fundamental<> = true | |
1e59de90 TL |
58 | boost::multiprecision::detail::is_signed<> = true |
59 | boost::multiprecision::detail::is_unsigned<> = false | |
60 | boost::multiprecision::detail::is_integral<> = false | |
61 | boost::multiprecision::detail::is_arithmetic<> = true | |
f67539c2 TL |
62 | std::is_const<> = false |
63 | std::is_trivial<> = true | |
64 | std::is_standard_layout<> = true | |
65 | std::is_pod<> = true | |
66 | std::numeric_limits::<>is_exact = false | |
67 | std::numeric_limits::<>is bounded = true | |
68 | std::numeric_limits::<>is_modulo = false | |
69 | std::numeric_limits::<>is_iec559 = true | |
70 | std::numeric_limits::<>traps = false | |
71 | std::numeric_limits::<>tinyness_before = false | |
72 | std::numeric_limits::<>max() = 1.18973149535723176508575932662800702e+4932 | |
73 | std::numeric_limits::<>min() = 3.36210314311209350626267781732175260e-4932 | |
74 | std::numeric_limits::<>lowest() = -1.18973149535723176508575932662800702e+4932 | |
75 | std::numeric_limits::<>min_exponent = -16381 | |
76 | std::numeric_limits::<>max_exponent = 16384 | |
77 | std::numeric_limits::<>epsilon() = 1.92592994438723585305597794258492732e-34 | |
78 | std::numeric_limits::<>radix = 2 | |
79 | std::numeric_limits::<>digits = 113 | |
80 | std::numeric_limits::<>digits10 = 33 | |
81 | std::numeric_limits::<>max_digits10 = 36 | |
82 | std::numeric_limits::<>has denorm = true | |
83 | std::numeric_limits::<>denorm min = 6.47517511943802511092443895822764655e-4966 | |
84 | std::denorm_loss = false | |
85 | limits::has_signaling_NaN == false | |
86 | std::numeric_limits::<>quiet_NaN = nan | |
87 | std::numeric_limits::<>infinity = inf | |
88 | ||
89 | //] [/float128_numeric_limits] | |
90 | */ | |
91 | ||
7c673cae | 92 |