https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932
Bug ID: 67932 Summary: Incorrect conversion to hexfloat Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: rcopley at gmail dot com Target Milestone: --- Created attachment 36481 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36481&action=edit Preprocessed source file that demonstrates incorrect conversion from floating-point value to string in hexfloat format In GCC 5.2, in C++11, converting a floating-point value to a string in hexadecimal floating-point (hexfloat) format gives incorrect results. The same incorrect results occur when using std::printf from <cstdio> or using the iostreams manipulator std::hexfloat. Using printf from <stdio.h> gives the correct results (even in C++). Output of gcc -v: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=C:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/5.2.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../../../src/gcc-5.2.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw520/x86_64-520-posix-seh-rt_v4-rev0/mingw64 --with-gxx-include-dir=/mingw64/x86_64-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw520/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw520/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw520/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw520/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw520/x86_64-520-posix-seh-rt_v4-rev0/mingw64/opt/include -I/c/mingw520/prerequisites/x86_64-zlib-static/include -I/c/mingw520/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw520/x86_64-520-posix-seh-rt_v4-rev0/mingw64/opt/include -I/c/mingw520/prerequisites/x86_64-zlib-static/include -I/c/mingw520/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw520/x86_64-520-posix-seh-rt_v4-rev0/mingw64/opt/lib -L/c/mingw520/prerequisites/x86_64-zlib-static/lib -L/c/mingw520/prerequisites/x86_64-w64-mingw32-static/lib ' Thread model: posix gcc version 5.2.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) Complete command line that triggers the bug: g++ -save-temps -std=c++11 -o hexfloat-bug.exe hexfloat-bug.cpp && hexfloat-bug.exe Compiler output: none. Preprocessed source file: see attached. Expected program output: 1.0000000000000002e+000 0x1.0000000000001p+0 0x1.000000p+0 1.0000000000000036e+000 0x1.0000000000010p+0 0x1.000000p+0 1.0000000000000568e+000 0x1.0000000000100p+0 0x1.000000p+0 1.0000000000009095e+000 0x1.0000000001000p+0 0x1.000000p+0 1.0000000000145519e+000 0x1.0000000010000p+0 0x1.000000p+0 1.0000000002328306e+000 0x1.0000000100000p+0 0x1.000000p+0 1.0000000037252903e+000 0x1.0000001000000p+0 0x1.000000p+0 1.0000000596046448e+000 0x1.0000010000000p+0 0x1.000001p+0 1.0000009536743164e+000 0x1.0000100000000p+0 0x1.000010p+0 1.0000152587890625e+000 0x1.0001000000000p+0 0x1.000100p+0 Actual program output: 1.0000000000000002e+000 0x8.0000000000000p-55 0x8p-55 1.0000000000000036e+000 0x8.0000000000000p-51 0x8p-51 1.0000000000000568e+000 0x8.0000000000000p-47 0x8p-47 1.0000000000009095e+000 0x8.0000000000000p-43 0x8p-43 1.0000000000145519e+000 0x8.0000000000000p-39 0x8p-39 1.0000000002328306e+000 0x8.0000000000000p-35 0x8p-35 1.0000000037252903e+000 0x8.0000008000000p-3 0x0p-63 1.0000000596046448e+000 0x8.0000080000000p-3 0x0p-63 1.0000009536743164e+000 0x0.0000000000000p-55 0x0p-63 1.0000152587890625e+000 0x0.0000000000000p-55 0x0p-63