> > When compiling with -O or greater optimization, and if x > INT_MAX, then code > like this: > uint64_t y = (uint64_t)round(x); > assigns the wrong value to y (the top 32 bits are all 1s). But this code > assigns the right value to z: > double dz = round(x); > uint64_t z = dz; > > It almost seems as if gcc -O in some cases compiles using a built-in > declaration of round() that returns a 32-bit int.
Yes this is wrong code, GCC is generating for some reason lround instead of llround. Thanks, Andrew Pinski