This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
compiler/library behavior differences?
- From: "W. Carlisle" <carliwh at auburn dot edu>
- To: <bug-gcc at gnu dot org>
- Date: Tue, 17 Oct 2006 12:25:37 -0500
- Subject: compiler/library behavior differences?
The following C program produces different results with Sun compiler,
ICC compiler and GCC compiler. Is it a rounding error due to
temporaries? Or is it in the printf library?
The other compilers seem to handle this better. I get same result
with cygwin and on linux, and believe both to be GCC.
#include <stdio.h>
#include <math.h>
int main() {
double d = log(8.0)/log(2.0);
printf("%d\n", (int) (d));
//prints 3
printf("%lf\n",log(8.0)/log(2.0));
//prints 3.000000
printf("%d\n", (int) ( log(8.0)/log(2.0)));
//prints 2
printf("%d\n", (int) (d=log(8.0)/log(2.0)));
//prints 2
printf("%d\n", (int) d);
//prints 3
}
Sun and ICC compilers give 3,3.000000,3,3,3
Linux compiler is GCC 3.4.4 20050721 RedHat 3.4.4-2
gcc prog.c -lm