public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21360] New: wrong result of 'if' statement with  comparing of floating point with gcc.
@ 2005-05-03 15:05 dtemirbulatov at ru dot mvista dot com
  2005-05-03 15:08 ` [Bug middle-end/21360] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: dtemirbulatov at ru dot mvista dot com @ 2005-05-03 15:05 UTC (permalink / raw)
  To: gcc-bugs

Following code produces wrong results:

#include <stdio.h>

float f = -1.0f ;

int main( void )
{

        if ( (unsigned int)f != (unsigned int)-1.0f ) {
                printf( "%-12s %04d:NG...[%u]--->[%u]\n",
                        __FILE__, __LINE__, (unsigned int)-1.0f, (unsigned int)f ) ;
        } else {
                printf( "[%u]--->[%u] :OK\n", (unsigned int)-1.0f, (unsigned
int)f ) ;
        }

        return( 0 ) ;
}

[dinar@dinar tmp]$ /home/dinar/work/gcc-builds/gnu/gcc-i686-pc-linux-gnu/bin/gcc
sample.c -o sample
[dinar@dinar tmp]$ ./sample
sample.c     0010:NG...[0]--->[4294967295]
[dinar@dinar tmp]$ /home/dinar/work/gcc-builds/gnu/gcc-i686-pc-linux-gnu/bin/gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure
--prefix=/home/dinar/work/gcc-builds/gnu/gcc-i686-pc-linux-gnu/
--enable-languages=c,c++
Thread model: posix
gcc version 4.1.0 20050429 (experimental)

-- 
           Summary: wrong result of 'if' statement with  comparing of
                    floating point with gcc.
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dtemirbulatov at ru dot mvista dot com
                CC: dtemirbulatov at ru dot mvista dot com,gcc-bugs at gcc
                    dot gnu dot org


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


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

* [Bug middle-end/21360] wrong result of 'if' statement with  comparing of floating point with gcc.
  2005-05-03 15:05 [Bug c/21360] New: wrong result of 'if' statement with comparing of floating point with gcc dtemirbulatov at ru dot mvista dot com
@ 2005-05-03 15:08 ` pinskia at gcc dot gnu dot org
  2005-05-03 15:10 ` dtemirbulatov at ru dot mvista dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-03 15:08 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end


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


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

* [Bug middle-end/21360] wrong result of 'if' statement with  comparing of floating point with gcc.
  2005-05-03 15:05 [Bug c/21360] New: wrong result of 'if' statement with comparing of floating point with gcc dtemirbulatov at ru dot mvista dot com
  2005-05-03 15:08 ` [Bug middle-end/21360] " pinskia at gcc dot gnu dot org
@ 2005-05-03 15:10 ` dtemirbulatov at ru dot mvista dot com
  2005-05-03 15:11 ` dtemirbulatov at ru dot mvista dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: dtemirbulatov at ru dot mvista dot com @ 2005-05-03 15:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dtemirbulatov at ru dot mvista dot com  2005-05-03 15:09 -------
Created an attachment (id=8806)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=8806&action=view)
testcase


-- 


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


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

* [Bug middle-end/21360] wrong result of 'if' statement with  comparing of floating point with gcc.
  2005-05-03 15:05 [Bug c/21360] New: wrong result of 'if' statement with comparing of floating point with gcc dtemirbulatov at ru dot mvista dot com
  2005-05-03 15:08 ` [Bug middle-end/21360] " pinskia at gcc dot gnu dot org
  2005-05-03 15:10 ` dtemirbulatov at ru dot mvista dot com
@ 2005-05-03 15:11 ` dtemirbulatov at ru dot mvista dot com
  2005-05-03 15:14 ` dtemirbulatov at ru dot mvista dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: dtemirbulatov at ru dot mvista dot com @ 2005-05-03 15:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dtemirbulatov at ru dot mvista dot com  2005-05-03 15:11 -------
Created an attachment (id=8807)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=8807&action=view)
proposed patch


-- 


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


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

* [Bug middle-end/21360] wrong result of 'if' statement with  comparing of floating point with gcc.
  2005-05-03 15:05 [Bug c/21360] New: wrong result of 'if' statement with comparing of floating point with gcc dtemirbulatov at ru dot mvista dot com
                   ` (2 preceding siblings ...)
  2005-05-03 15:11 ` dtemirbulatov at ru dot mvista dot com
@ 2005-05-03 15:14 ` dtemirbulatov at ru dot mvista dot com
  2005-05-03 15:21 ` [Bug middle-end/21360] [3.4/4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: dtemirbulatov at ru dot mvista dot com @ 2005-05-03 15:14 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |3.4.0 4.0.0 4.1.0
      Known to work|                            |3.3.5


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


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

* [Bug middle-end/21360] [3.4/4.0/4.1 Regression] wrong result of 'if' statement with  comparing of floating point with gcc.
  2005-05-03 15:05 [Bug c/21360] New: wrong result of 'if' statement with comparing of floating point with gcc dtemirbulatov at ru dot mvista dot com
                   ` (3 preceding siblings ...)
  2005-05-03 15:14 ` dtemirbulatov at ru dot mvista dot com
@ 2005-05-03 15:21 ` pinskia at gcc dot gnu dot org
  2005-05-03 16:35 ` jsm28 at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-03 15:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-03 15:21 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2005-05-03 15:21:14
               date|                            |
            Summary|wrong result of 'if'        |[3.4/4.0/4.1 Regression]
                   |statement with  comparing of|wrong result of 'if'
                   |floating point with gcc.    |statement with  comparing of
                   |                            |floating point with gcc.
   Target Milestone|---                         |3.4.4


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


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

* [Bug middle-end/21360] [3.4/4.0/4.1 Regression] wrong result of 'if' statement with  comparing of floating point with gcc.
  2005-05-03 15:05 [Bug c/21360] New: wrong result of 'if' statement with comparing of floating point with gcc dtemirbulatov at ru dot mvista dot com
                   ` (4 preceding siblings ...)
  2005-05-03 15:21 ` [Bug middle-end/21360] [3.4/4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
@ 2005-05-03 16:35 ` jsm28 at gcc dot gnu dot org
  2005-05-04  1:22 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2005-05-03 16:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm28 at gcc dot gnu dot org  2005-05-03 16:33 -------
Conversion of out-of-range floating point values to integers yields undefined
behavior in both C and C++.  There is no need for it to be consistent between
compile-time and runtime conversions.

However, the ISO C decimal floating point proposals (DTR 24732 / WG14 N1107)
make it well-defined for binary as well as decimal floating-point types.  So we
do want to support well-defined semantics (namely, those in that proposal) for
both compile-time and runtime conversions, at least under a command-line option
to enable them.  I don't know whether dfp-branch has such support yet. 
Performance measurements would be needed to ascertain whether there is any
benefit to having both versions or whether we might as well just always use the
DTR 24732 semantics for these conversions (and document that we are doing so,
and seek out and eliminate any optimizations in the compiler which depend on
such conversions being undefined - a search for such optimizations being a
necessary part of the decimal floating point work anyway if not already done).


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bje at gcc dot gnu dot org


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


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

* [Bug middle-end/21360] [3.4/4.0/4.1 Regression] wrong result of 'if' statement with  comparing of floating point with gcc.
  2005-05-03 15:05 [Bug c/21360] New: wrong result of 'if' statement with comparing of floating point with gcc dtemirbulatov at ru dot mvista dot com
                   ` (5 preceding siblings ...)
  2005-05-03 16:35 ` jsm28 at gcc dot gnu dot org
@ 2005-05-04  1:22 ` pinskia at gcc dot gnu dot org
  2005-05-10  1:51 ` [Bug middle-end/21360] " mmitchel at gcc dot gnu dot org
  2005-06-29 21:59 ` jsm28 at gcc dot gnu dot org
  8 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-04  1:22 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor


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


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

* [Bug middle-end/21360] wrong result of 'if' statement with  comparing of floating point with gcc.
  2005-05-03 15:05 [Bug c/21360] New: wrong result of 'if' statement with comparing of floating point with gcc dtemirbulatov at ru dot mvista dot com
                   ` (6 preceding siblings ...)
  2005-05-04  1:22 ` pinskia at gcc dot gnu dot org
@ 2005-05-10  1:51 ` mmitchel at gcc dot gnu dot org
  2005-06-29 21:59 ` jsm28 at gcc dot gnu dot org
  8 siblings, 0 replies; 11+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-05-10  1:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mmitchel at gcc dot gnu dot org  2005-05-10 01:51 -------
To the extent this is a bug, it's a failure to comply to a future standard.  As
such, it's certainly not release-critical, and it's not even really a
regression.  Removed target milestone and regression markers.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[3.4/4.0/4.1 Regression]    |wrong result of 'if'
                   |wrong result of 'if'        |statement with  comparing of
                   |statement with  comparing of|floating point with gcc.
                   |floating point with gcc.    |
   Target Milestone|3.4.4                       |---


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


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

* [Bug middle-end/21360] wrong result of 'if' statement with  comparing of floating point with gcc.
  2005-05-03 15:05 [Bug c/21360] New: wrong result of 'if' statement with comparing of floating point with gcc dtemirbulatov at ru dot mvista dot com
                   ` (7 preceding siblings ...)
  2005-05-10  1:51 ` [Bug middle-end/21360] " mmitchel at gcc dot gnu dot org
@ 2005-06-29 21:59 ` jsm28 at gcc dot gnu dot org
  8 siblings, 0 replies; 11+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2005-06-29 21:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm28 at gcc dot gnu dot org  2005-06-29 21:59 -------
It's come to my attention that C99 Annex F.4#1 specifies that the result is an
unspecified value, with the "invalid" exception raised at runtime, rather than
undefined behavior (in the absence of defining __STDC_IEC_559__, it's still
undefined behavior).  We don't currently implement FENV_ACCESS at all so the
exception is irrelevant and I don't think we currently have any optimizations
relying on the conversion being undefined rather than unspecified, but in any
case the decimal fp work will answer the questions of what optimizations we do
here and whether there is any performance cost to defining the results the way
the decimal fp proposals do unconditionally.


-- 


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


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

* [Bug middle-end/21360] wrong result of 'if' statement with  comparing of floating point with gcc.
       [not found] <bug-21360-9794@http.gcc.gnu.org/bugzilla/>
@ 2007-09-23 12:47 ` rguenth at gcc dot gnu dot org
  0 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-09-23 12:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2007-09-23 12:47 -------
6.3.1.4/1 says this is undefined.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2007-09-23 12:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-03 15:05 [Bug c/21360] New: wrong result of 'if' statement with comparing of floating point with gcc dtemirbulatov at ru dot mvista dot com
2005-05-03 15:08 ` [Bug middle-end/21360] " pinskia at gcc dot gnu dot org
2005-05-03 15:10 ` dtemirbulatov at ru dot mvista dot com
2005-05-03 15:11 ` dtemirbulatov at ru dot mvista dot com
2005-05-03 15:14 ` dtemirbulatov at ru dot mvista dot com
2005-05-03 15:21 ` [Bug middle-end/21360] [3.4/4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
2005-05-03 16:35 ` jsm28 at gcc dot gnu dot org
2005-05-04  1:22 ` pinskia at gcc dot gnu dot org
2005-05-10  1:51 ` [Bug middle-end/21360] " mmitchel at gcc dot gnu dot org
2005-06-29 21:59 ` jsm28 at gcc dot gnu dot org
     [not found] <bug-21360-9794@http.gcc.gnu.org/bugzilla/>
2007-09-23 12:47 ` rguenth 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).