I was confused about the "php" == 0, until I found http://php.net/manual/en/types.comparisons.php . So "php" == 0 is true and "php" == true is true, but 0 == true is false. Yikes! It seems like comparisons in PHP are as bad as they are in JS. I have a hard time believing this is real. Does WTF do any verification?
Divine By Zero
21–26 of 26 posts
Re: Divine By Zero
#22As much as I love TDWTF I have to say I'm disappointed to see a submission from there get 46 upvotes on the front page. Great story though
I doubt it, but I guess it's at least possible that someone here works with the criminally insane.
Re: Divine By Zero
#23As much as I love TDWTF I have to say I'm disappointed to see a submission from there get 46 upvotes on the front page. Great story though
Re: Divine By Zero
#24Lets say for a moment that this isn't made up. The questions that struck me immediately are as follows: 1. What was the motivation for creating this function? Was it (hopefully) to show off how "smart" he was? Was the company he worked for doing any kind of calculations related to (dear god no) financial or medical data that he thought he could improve? 2. How does anyone in this world escape grade school without kno…
Re: Divine By Zero
#25Lets say for a moment that this isn't made up. The questions that struck me immediately are as follows: 1. What was the motivation for creating this function? Was it (hopefully) to show off how "smart" he was? Was the company he worked for doing any kind of calculations related to (dear god no) financial or medical data that he thought he could improve? 2. How does anyone in this world escape grade school without kno…
result = (A-B)./A*100;
Now I can just use the isfinite function to produce a matrix of logical values that tells me which pixel locations have valid values (simultaneously handling the case of numerical overflow). Granted, this doesn't do much to simplify the code above. We could have just checked beforehand to find the pixels of A that had zero values. However, if you have a complicated expression involving multiple divisions, logarithms, or other functions that are undefined for some portion of the real numbers, treating these situations as "recoverable" in some sense allows you to write cleaner, more readable code if your implementation language permits you to just do the operation and check for NaN values (+Inf and -Inf too) afterward.
Re: Divine By Zero
#26Is there an opposite website to The Daily WTF - a collection of short, elegant and clever code?
http://www.amazon.com/Programming-Pearls-2nd-Jon-Bentley/dp/...