]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multiprecision/example/cpp_bin_float_import_export.cpp
1 ///////////////////////////////////////////////////////////////
2 // Copyright 2015 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
6 #include <boost/multiprecision/cpp_bin_float.hpp>
12 // Contains Quickbook snippets in comments.
17 Importing or exporting cpp_bin_float is similar, but we must procede via an intermediate integer:
20 #include <boost/multiprecision/cpp_bin_float.hpp>
29 using boost::multiprecision::cpp_bin_float_100
;
30 using boost::multiprecision::cpp_int
;
31 // Create a cpp_bin_float to import/export:
32 cpp_bin_float_100
f(1);
34 // export into 8-bit unsigned values, most significant bit first:
35 std::vector
<unsigned char> v
;
36 export_bits(cpp_int(f
.backend().bits()), std::back_inserter(v
), 8);
37 // Grab the exponent as well:
38 int e
= f
.backend().exponent();
39 // Import back again, and check for equality, we have to procede via
40 // an intermediate integer:
42 import_bits(i
, v
.begin(), v
.end());
43 cpp_bin_float_100
g(i
);
44 g
.backend().exponent() = e
;