GCC compile time division error

Posted by kartikmohta on Stack Overflow See other posts from Stack Overflow or by kartikmohta
Published on 2010-06-03T04:34:46Z Indexed on 2010/06/03 4:44 UTC
Read the original article Hit count: 170

Filed under:
|
|

Can someone explain this behaviour?

test.c:

#include <stdio.h>

int main(void)
{
    printf("%d, %d\n", (int) (300.6000/0.05000), (int) (300.65000/0.05000));
    printf("%f, %f\n", (300.6000/0.05000), (300.65000/0.05000));
    return 0;
}

$ gcc test.c

$ ./a.out
6012, 6012
6012.000000, 6013.000000

I checked the assembly code and it puts both the arguments of the first printf as 6012, so it seems to be a compile time bug.

© Stack Overflow or respective owner

Related posts about c

    Related posts about gcc