3 ms·
More pernicious is you may think that the result of a computation should be an exact number, but it may not be. Consider: #include "stdio.h" int main()
by scott_s 14y ago
More pernicious is you may think that the result of a computation should be an exact number, but it may not be. Consider:
#include "stdio.h"
int main()
{
double num = 3.0;
unsigned long long i;
for (i = 0; i < 1000000000; ++i) {
num += 1e-9;
}
printf("%f\n", num);
printf("%llx\n", *((unsigned long long*)&num));
double four = 4.0;
printf("%f\n", four);
printf("%llx\n", *((unsigned long long*)&four));
return 0;
}
And then executed,
[scott_s@local ~] ./float
4.000000
40100000058d7800
4.000000
4010000000000000