Opened 9 years ago
Closed 9 years ago
#8745 closed Bugs (fixed)
stream operator << for number/cpp_int_backend with 8 bit or less precision not working
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | To Be Determined | Component: | multiprecision |
Version: | Boost 1.53.0 | Severity: | Problem |
Keywords: | multiprecision cpp_int_backend stream | Cc: |
Description
for 8 bit or less numbers << with hex format sets characters to the numeric value of their digit rather than the ascii value. ie if the character should be 'F' the returned value is 15 rather than the ASCII value for F.
number<cpp_int_backend<7, 7, unsigned_magnitude, unchecked, void>> myNum07( "0xF"); number<cpp_int_backend<8, 8, unsigned_magnitude, unchecked, void>> myNum08( "0x0F"); number<cpp_int_backend<9, 9, unsigned_magnitude, unchecked, void>> myNum09( "0x0F"); number<cpp_int_backend<16, 16, unsigned_magnitude, unchecked, void>> myNum16("0x000F");
char outBuf[1000]; std::stringstream ss; ss << setfill('0'); ss << "7 bit : " << std::setw(2) << std::hex << myNum07 << endl; ss << "8 bit : " << std::setw(2) << std::hex << myNum08 << endl; ss << "9 bit : " << std::setw(2) << std::hex << myNum09 << endl; ss << "16 bit: " << std::setw(2) << std::hex << myNum16 << endl; strncpy(outBuf, ss.str().c_str(), 999); printf("%s\n", outBuf);
output is:
7 bit : 0☼ 8 bit : 0☼ 9 bit : 0f 16 bit: 0f
(In [84928]) Correct output of small-integer types. Fixes #8745.