public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* compiler/library behavior differences?
@ 2006-10-17 17:26 W. Carlisle
0 siblings, 0 replies; only message in thread
From: W. Carlisle @ 2006-10-17 17:26 UTC (permalink / raw)
To: bug-gcc
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-10-17 17:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-17 17:26 compiler/library behavior differences? W. Carlisle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).