#include <math.h> typedef long long llong; int main(int argc,char **argv){; int ex=0; llong num_z=0xf70694892bddbb3f,num_x=0x0000000000f88640;double *z_p=(void *)&num_z,*x_p=(void *)&num_x; static int le_v=1;char *le=(void *)&le_v;if(le[0]) { llong num_z2=0,num_x2=0;int n=0;while(n<sizeof(llong)) { num_z2<<=8;num_z2|=num_z&0xFF;num_z>>=8; num_x2<<=8;num_x2|=num_x&0xFF;num_x>>=8;n+=1; } num_z=num_z2;num_x=num_x2; }double c_f=z_p[0]*x_p[0];int a=floor(z_p[0]*x_p[0]),b=z_p[0]*x_p[0],c=c_f;if(a!=b)dprintf(2,"%d %d %d\n",a,b,c); if(1)dprintf(2,"%.15lf %.15lf %.15lf\n",z_p[0],x_p[0],c_f); return ex;}; /*fn=;gcc $fn.c -o $fn -lm -include stdio.h&&$fn*/
I get the result of 80 for a, b and c on x86_64-linux-gnu (even with -m32) and across compilers, GCC, clang and ICC. What target are you using?
i686-linux-gnu if change c_f to long double and use llf, brings c_f down and brings c down to b
This is just an artifact of x87 and how everything is done in 80bit fp and sometimes you get different answers than you are expected. If SSE2 is turned on, then the integer to fp conversion happens in the SSE2 unit and is converted to 64bit fp before the conversion. Again this is not really a bug, but a partial misunderstanding of floating point and how x87 floating point works. *** This bug has been marked as a duplicate of bug 323 ***
it works with -mpc64 so the default was set to the highest, but I guess should have been limited by the target