public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40809]  New: wrong conversion from unsigned int to float
@ 2009-07-20 19:52 foldy at rmki dot kfki dot hu
  2009-07-20 21:13 ` [Bug target/40809] " hjl dot tools at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: foldy at rmki dot kfki dot hu @ 2009-07-20 19:52 UTC (permalink / raw)
  To: gcc-bugs

The following program produces wrong results at -m64 -O3:

// a.cc

#include <iostream>

#define N 5

void
cvt_u4_f4(int n, unsigned int* u4, float* f4)
{
    for (int j=0; j<n; j++)
         f4[j]=u4[j];
}


int main()
{
  unsigned int u4[N];
  float f4[N];

  for (unsigned int j=0; j<N; j++) u4[j]=4000000000u+j;

  cvt_u4_f4(N, u4, f4);

  for (int j=0; j<N; j++) std::cout << f4[j] << std::endl;
}

g++-4.4 -m64 -O3 a.cc && ./a.out prints:

-2.94967e+08
-2.94967e+08
-2.94967e+08
-2.94967e+08
4e+09

At -O0/-O1/-O2 the results are correct:

4e+09
4e+09
4e+09
4e+09
4e+09


-- 
           Summary: wrong conversion from unsigned int to float
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: foldy at rmki dot kfki dot hu
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809


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

end of thread, other threads:[~2009-07-21 15:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-20 19:52 [Bug c++/40809] New: wrong conversion from unsigned int to float foldy at rmki dot kfki dot hu
2009-07-20 21:13 ` [Bug target/40809] " hjl dot tools at gmail dot com
2009-07-20 21:16 ` hjl dot tools at gmail dot com
2009-07-20 22:47 ` ubizjak at gmail dot com
2009-07-20 22:51 ` hjl dot tools at gmail dot com
2009-07-20 23:12 ` ubizjak at gmail dot com
2009-07-21  9:58 ` uros at gcc dot gnu dot org
2009-07-21 10:01 ` ubizjak at gmail dot com
2009-07-21 15:17 ` uros at gcc dot gnu dot 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).