3 ms·
implicit int to double is really, really bad! it can silently truncate - double can only store 53 bits integers so for large integers the result will not be an
by nextaccountic 4y ago
implicit int to double is really, really bad! it can silently truncate - double can only store 53 bits integers so for large integers the result will not be an integer!
in general, lossy conversions should never, ever be implicit
- compiler-devel 4y agoGreat point, I was thinking of ints as 32 bits. You're absolutely correct for 64 bit ints!
- dataflow 4y agoI would instead say int should be guaranteed to fit in a double. I feel like there's no reason to introduce a pitfall in > 99.999% of use cases just because there might be some obscure architecture where int is 64-bit and its programmers cannot be bothered with the extra keystroke for 'long'.