public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/67932] New: Incorrect conversion to hexfloat
@ 2015-10-12 12:50 rcopley at gmail dot com
  2015-10-12 13:54 ` [Bug libstdc++/67932] " redi at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: rcopley at gmail dot com @ 2015-10-12 12:50 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/67932] Incorrect conversion to hexfloat
  2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
@ 2015-10-12 13:54 ` redi at gcc dot gnu.org
  2015-10-12 17:20 ` rcopley at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2015-10-12 13:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Your preprocessed source doesn't use std::hexfloat, so any problem comes from
std::printf, which is part of your C library not part of GCC.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/67932] Incorrect conversion to hexfloat
  2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
  2015-10-12 13:54 ` [Bug libstdc++/67932] " redi at gcc dot gnu.org
@ 2015-10-12 17:20 ` rcopley at gmail dot com
  2015-10-12 20:59 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rcopley at gmail dot com @ 2015-10-12 17:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932

--- Comment #2 from R Copley <rcopley at gmail dot com> ---
Thanks Jonathan. It's clear enough from what I wrote that:

(1) The same kind of incorrect output is produced by (a) including <cstdio> and
using std::printf, and (b) using iostreams and std::hexfloat;

(2) The correct output is produced by including <stdio.h> and using ::printf.

I think (but I am by no means certain!) that (by (2)) my C library works, and
(by (1)) there is a problem with GCC's standard library implementation.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/67932] Incorrect conversion to hexfloat
  2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
  2015-10-12 13:54 ` [Bug libstdc++/67932] " redi at gcc dot gnu.org
  2015-10-12 17:20 ` rcopley at gmail dot com
@ 2015-10-12 20:59 ` redi at gcc dot gnu.org
  2015-10-12 21:41 ` rcopley at gmail dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2015-10-12 20:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Libstdc++ has no implementation of printf, so ::printf and std::printf are
exactly the same function, with std::printf defined as:

namespace std
{
  using ::printf;
}


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/67932] Incorrect conversion to hexfloat
  2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
                   ` (2 preceding siblings ...)
  2015-10-12 20:59 ` redi at gcc dot gnu.org
@ 2015-10-12 21:41 ` rcopley at gmail dot com
  2015-10-12 21:42 ` rcopley at gmail dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rcopley at gmail dot com @ 2015-10-12 21:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932

--- Comment #4 from R Copley <rcopley at gmail dot com> ---
That's what I understood to be the case. Nevertheless, with the toolchain I am
using (see above for version; same command-line etc.), I get the results below. 

Both testcases below give the correct results with g++-4.8 on Ubuntu (the idea
of installing 5.2 seems to confuse and infuriate the community there), so I
think I must report this to the MinGW-W64 maintainers instead. Thanks.

#include <stdio.h>
int main () { printf ("%a", 0x1.000008p+0); }
// Preprocessed source: see attachment "hexfloat-bug-2a.ii"
// Output: 0x1.000008p+0

#include <cstdio>
int main () { printf /*sic*/ ("%a", 0x1000008p+0); }
// Preprocessed source: see attachment "hexfloat-bug-2b.ii"
// Output: 0x0p-63


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/67932] Incorrect conversion to hexfloat
  2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
                   ` (4 preceding siblings ...)
  2015-10-12 21:42 ` rcopley at gmail dot com
@ 2015-10-12 21:42 ` rcopley at gmail dot com
  2015-10-12 22:23 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rcopley at gmail dot com @ 2015-10-12 21:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932

--- Comment #6 from R Copley <rcopley at gmail dot com> ---
Created attachment 36490
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36490&action=edit
hexfloat-bug-2b.ii (see Comment 4)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/67932] Incorrect conversion to hexfloat
  2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
                   ` (3 preceding siblings ...)
  2015-10-12 21:41 ` rcopley at gmail dot com
@ 2015-10-12 21:42 ` rcopley at gmail dot com
  2015-10-12 21:42 ` rcopley at gmail dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rcopley at gmail dot com @ 2015-10-12 21:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932

--- Comment #5 from R Copley <rcopley at gmail dot com> ---
Created attachment 36489
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36489&action=edit
hexfloat-bug-2a.ii (see Comment 4)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/67932] Incorrect conversion to hexfloat
  2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
                   ` (5 preceding siblings ...)
  2015-10-12 21:42 ` rcopley at gmail dot com
@ 2015-10-12 22:23 ` redi at gcc dot gnu.org
  2015-10-12 23:29 ` rcopley at gmail dot com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2015-10-12 22:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The difference will probably be that when including libstdc++'s <cstdio> this
happens before mingw's <stdio.h> is included:

// Make sure that POSIX printf/scanf functions are activated.  As
// libstdc++ depends on POSIX-definitions of those functions, we define
// it unconditionally.
#undef __USE_MINGW_ANSI_STDIO
#define __USE_MINGW_ANSI_STDIO 1

That alters what <stdio.h> declares, due to this in <stdio.h>

#if __USE_MINGW_ANSI_STDIO
/*
 * User has expressed a preference for C99 conformance...
 */

That causes printf to be a wrapper around __mingw_vprintf, rather than calling
the MSVCRT version:

__mingw_ovr
__attribute__((__format__ (gnu_printf, 1, 2))) __MINGW_ATTRIB_NONNULL(1)
int printf (const char *__format, ...)
{
  register int __retval;
  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
  __retval = __mingw_vprintf( __format, __local_argv );
  __builtin_va_end( __local_argv );
  return __retval;
}

So the incorrect output seems to come from __mingw_vprintf.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/67932] Incorrect conversion to hexfloat
  2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
                   ` (6 preceding siblings ...)
  2015-10-12 22:23 ` redi at gcc dot gnu.org
@ 2015-10-12 23:29 ` rcopley at gmail dot com
  2015-10-13 14:44 ` rcopley at gmail dot com
  2015-10-13 14:55 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rcopley at gmail dot com @ 2015-10-12 23:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932

--- Comment #8 from R Copley <rcopley at gmail dot com> ---
Thanks. I've emailed the mingw-w64 list at
http://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public. (You expressed it
better but I hadn't seen your last comment.)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/67932] Incorrect conversion to hexfloat
  2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
                   ` (7 preceding siblings ...)
  2015-10-12 23:29 ` rcopley at gmail dot com
@ 2015-10-13 14:44 ` rcopley at gmail dot com
  2015-10-13 14:55 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rcopley at gmail dot com @ 2015-10-13 14:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932

--- Comment #9 from R Copley <rcopley at gmail dot com> ---
For information, this has already been entered on the mingw-w64 issue tracker
(months ago) (see http://sourceforge.net/p/mingw-w64/bugs/459/).


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/67932] Incorrect conversion to hexfloat
  2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
                   ` (8 preceding siblings ...)
  2015-10-13 14:44 ` rcopley at gmail dot com
@ 2015-10-13 14:55 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2015-10-13 14:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67932

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                URL|                            |http://sourceforge.net/p/mi
                   |                            |ngw-w64/bugs/459/
         Resolution|---                         |MOVED

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Thanks for the link.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-10-13 14:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-12 12:50 [Bug libstdc++/67932] New: Incorrect conversion to hexfloat rcopley at gmail dot com
2015-10-12 13:54 ` [Bug libstdc++/67932] " redi at gcc dot gnu.org
2015-10-12 17:20 ` rcopley at gmail dot com
2015-10-12 20:59 ` redi at gcc dot gnu.org
2015-10-12 21:41 ` rcopley at gmail dot com
2015-10-12 21:42 ` rcopley at gmail dot com
2015-10-12 21:42 ` rcopley at gmail dot com
2015-10-12 22:23 ` redi at gcc dot gnu.org
2015-10-12 23:29 ` rcopley at gmail dot com
2015-10-13 14:44 ` rcopley at gmail dot com
2015-10-13 14:55 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).