float to int conversion
Andrew Haley
aph@redhat.com
Mon Apr 22 08:32:00 GMT 2013
On 04/22/2013 09:25 AM, Warlich, Christof wrote:
>
> imho, float to int conversion is wrong when the float exceeds the integer range:
>
> $ cat test1.c
> #include <stdio.h>
> int main() {
> float a = 1.23e24f;
> printf("%d, %d\n", (int) a, (int) 1.23e24f);
> return 0;
> }
>
>
> Is this a (known) bug, shall it be reported?
No.
"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."
Andrew.
More information about the Gcc-help
mailing list