RE: float to int conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andrew Haley [aph@xxxxxxxxxx] 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux