3 ms·
Good old IEEE 64bit floating point numbers =) That also means that for(i=0;i<j;++i){} doesn't necessarily terminate for an arbitrary j smaller than infinity, w
by Kenji 11y ago
Good old IEEE 64bit floating point numbers =)
That also means that for(i=0;i<j;++i){} doesn't necessarily terminate for an arbitrary j smaller than infinity, which I find hilarious.
- mikeash 11y agoI'd prefer an example along the lines of: for(i = j; i < j + 2; i++) {} With your example it's easy to lose the distinction between "would eventually terminate if you had a fast computer and a lot of time" and "never terminates even in theory." Here, it definitely looks like it should always run two iterations to matter what the numbers are (as long as they're finite), but it doesn't. Either way, though, it is definitely hilarious!
- eru 11y agoThanks to undefined behaviour, C compilers can assume that you get exactly two iterations for this kind of loop on ints.
- mark-r 11y agoIt terminates for an arbitrary j smaller than 2^53, which is enough for most people.