[Boost-bugs] [Boost C++ Libraries] #12627: export_bits() gives wrong answer on fixed precision type

Subject: [Boost-bugs] [Boost C++ Libraries] #12627: export_bits() gives wrong answer on fixed precision type
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-11-27 21:10:52


#12627: export_bits() gives wrong answer on fixed precision type
-------------------------------------------------+-------------------------
 Reporter: John Galbraith <john.galbraith17@…> | Owner: johnmaddock
     Type: Bugs | Status: new
Milestone: To Be Determined | Component:
  Version: Boost 1.62.0 | multiprecision
 Keywords: | Severity: Problem
-------------------------------------------------+-------------------------
 The following minimal working example prints the wrong answer. Compiled
 on Ubuntu 16.04,
 and the console prints:

 {{{
 âžœ ~ clang++ -std=c++14 bug.cpp
 âžœ ~ ./a.out
 FEDCBA9876543210F1E2D3C4B5A69788
 f1e2d3c4b5a69788f1e2d3c4b5a69788
 âžœ ~
 }}}

 I think those numbers should be the same, and they are different. It
 behaves like the low order 64 bits got serialized twice, and the high
 order 64 bits never got serialized at all.

 If you change the number type from uint128_t to cpp_int, then the example
 runs fine which is why I think this problem occurs only with fixed
 precision types.

 {{{
 #include <boost/multiprecision/cpp_int.hpp>
 #include <iostream>
 #include <vector>
 #include <cstdint>

 namespace mp = boost::multiprecision;

 int main() {

     mp::uint128_t i = mp::uint128_t(0xFEDCBA9876543210) << 64 |
 0xF1E2D3C4B5A69788;

     std::cout << std::hex << i << std::endl;

     std::vector<std::uint8_t> v(16);
     export_bits(i, v.begin(), 8);
     std::for_each(v.begin(), v.end(), [](std::uint8_t byte) { std::cout <<
 (int)byte; });
     std::cout << std::endl;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12627>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC