Hacker News new | past | comments | ask | show | jobs | submit login

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.




I'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!


Thanks to undefined behaviour, C compilers can assume that you get exactly two iterations for this kind of loop on ints.


It terminates for an arbitrary j smaller than 2^53, which is enough for most people.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: