3 ms·
Are you saying that a floating point value just under 4 won't necessarily cast to 3 or something else? (I'm reading the above posted links, but am intrigued at
by MikeDucker 14y ago
Are you saying that a floating point value just under 4 won't necessarily cast to 3 or something else?
(I'm reading the above posted links, but am intrigued at what I've gotten wrong with my statement you quoted)
- monochromatic 14y ago4 is represented exactly. (But 0.4 isn't.)
- MikeDucker 14y agoAh, I see. I'll update my post. Thanks.
- scott_s 14y agoMore 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