public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/27682]  New: float to int conversion doesn't raise invalid exception
@ 2006-05-19 16:08 janis at gcc dot gnu dot org
  2006-05-19 16:14 ` [Bug target/27682] " janis at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: janis at gcc dot gnu dot org @ 2006-05-19 16:08 UTC (permalink / raw)
  To: gcc-bugs

GCC claims to follow C99 Annex F when converting a floating value to an integer
type when the integral part exceeds the range of the integer type (C99 6.3.1.4
and F.4).  Annex F says that in this case the conversion raises the "invalid"
floating-point exception.  On powerpc64-linux and x86_64-linux, however, the
instruction that is used to convert double to int converts to a 64-bit integer,
not a 32-bit register, so the exception is not raised.  On powerpc64-linux with
-m64 the instruction is fctidz (floating convert to integer doubleword with
round toward zero).  If I replace that instruction with fctiwz (convert to
integer word) in the .s file and compile that, the code behaves as expected. 
Here's a small test case:

#include <fenv.h>
extern void abort (void);

double x = 4294967296.0;
unsigned int i;

int
main ()
{
#pragma STDC FENV_ACCESS ON
    feclearexcept (FE_ALL_EXCEPT);
    i = x;    /* value exceeds the range of 32-bit int */
    if (! fetestexcept (FE_INVALID))
        abort ();
    return 0;
}

I see this behavior in all powerpc64-linux compilers I've checked from 3.2
through mainline.  The exception is raised for tests compiled with -m32.

This is a problem for applications that try to detect such invalid conversions
after checking for __STDC_IEC_559__, which claims that the implementation
conforms to Annex F.

A possibly-related issue is that this macro is defined in a header file
provided by glibc, not by GCC.


-- 
           Summary: float to int conversion doesn't raise invalid exception
           Product: gcc
           Version: 4.0.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janis at gcc dot gnu dot org
GCC target triplet: powerpc64-linux, x86_64-linux


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


^ permalink raw reply	[flat|nested] 12+ messages in thread
[parent not found: <bug-27682-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2010-10-05 18:31 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-19 16:08 [Bug target/27682] New: float to int conversion doesn't raise invalid exception janis at gcc dot gnu dot org
2006-05-19 16:14 ` [Bug target/27682] " janis at gcc dot gnu dot org
2006-05-19 16:22 ` pinskia at gcc dot gnu dot org
2006-05-19 16:36 ` joseph at codesourcery dot com
2006-05-19 17:25 ` janis at gcc dot gnu dot org
2006-05-29  2:48 ` amodra at bigpond dot net dot au
2006-05-29  2:52 ` amodra at bigpond dot net dot au
2006-05-30 16:59 ` janis at gcc dot gnu dot org
2008-06-24  8:23 ` aldot at gcc dot gnu dot org
2009-01-31 20:16 ` tydeman at tybor dot com
2009-05-14  3:47 ` bje at gcc dot gnu dot org
     [not found] <bug-27682-4@http.gcc.gnu.org/bugzilla/>
2010-10-05 18:31 ` pinskia 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).