News for hackers. Stuff that matters.
Re:A Quick Puzzle to Test Your Problem Solving by Kenji on Thursday July 02, 2015 @10:35AM (#9819137)
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.

Re:A Quick Puzzle to Test Your Problem Solving by mikeash on Thursday July 02, 2015 @01:58PM (#9820505)
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!

Re:A Quick Puzzle to Test Your Problem Solving by eru on Friday July 03, 2015 @12:43AM (#9823526)
Thanks to undefined behaviour, C compilers can assume that you get exactly two iterations for this kind of loop on ints.
Re:A Quick Puzzle to Test Your Problem Solving by mark-r on Friday July 03, 2015 @12:07AM (#9823392)
It terminates for an arbitrary j smaller than 2^53, which is enough for most people.