This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: float to int conversion


Andrew Haley [aph@redhat.com] wrote:
>    "When a finite value of real floating type is converted to an integer
>    type other than _Bool, the fractional part is discarded (i.e., the
>    value is truncated toward zero). If the value of the integral part
>    cannot be represented by the integer type, the behavior is
>    undefined."

Ok, fair enough. But then, what about my second example?:

> > $ cat test2.c
> > #include <stdio.h>
> > int main() {
> >     float c = 0x7fffffbf;
> >    float d = 0x7fffffc0;
> >    printf("%d, %d\n", (int) c, (int) d);   
> >    return 0;
> > }
> > 
> > $ gcc test2.c
> > $ ./a.out
> > 2147483520, -2147483648

There, the float _does_ fit into an integer by definition, but it still
yields the wrong result. 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]