Code example:
#include <stdio.h>
int main() {
printf("%d", (int)4294967295.0);
return 0;
}
This prints 2147483647 on code code ( http://codepad.org/yDCqFdTT ) and -2147483648 in vs2012 settings. -1 expected. However, converting 4294967295.0 to an unsigned integer gives -1.
What's happening? How can I safely convert my double to int? This type of error is outside the range of rounding errors.
source
share