3

When calling export_bits on a negative boost::multiprecision number based on cpp_int, an exception is thrown from the internal method msb ("testing individual bits in negative values is not supported"). (Boost 1.60)

boost::multiprecision::checked_int128_t i (-1); // use negative number
std::vector<unsigned char> v;
export_bits(i, std::back_inserter(v), 8);  // throws

How can I extract the content of a boost::multiprecision number? Boost documentation says, export_bits is designed to be used for data exchange, so in my understanding it would be a major flaw, if it cannot export supported values.

I learnt that a workaround might be to directly access the backend's limbs, but it is accessing internals that may change.

Update: I posted the question on the boost mailinglist, opened a ticket for this https://svn.boost.org/trac/boost/ticket/12170, and it will be fixed in an upcoming release.

http://www.boost.org/doc/libs/master/libs/multiprecision/doc/html/boost_multiprecision/tut/import_export.html

Community
  • 1
  • 1
ta55e
  • 194
  • 8

0 Answers0