Divine By Zero
thedailywtf.com
thedailywtf.com
I have a hard time believing this is real. Does WTF do any verification?
http://www.amazon.com/Programming-Pearls-2nd-Jon-Bentley/dp/...
After spending a couple years specializing with Drupal I'd almost forgotten how ridiculous it can get out in the trenches.
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 knowing that one cannot divide by zero?
3. Someone thought dividing by zero should be a recoverable error?
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.
I doubt it, but I guess it's at least possible that someone here works with the criminally insane.
Aside from the whole function being asinine the only way to know "why" would be to ask him. The answer would probably also qualify as asinine.