- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Javadocs use something similar, just not XML. You can put useless comments there. But if someone does take the time to add meaningful comments, it's nice to have a tool to pull those out for you.
If someone is going to fill out the comment like you show above, they wouldn't have added a better comment without the markup either.
Admin
Admin
And you might shot yourself in a leg if given a gun. I personally think XML comments are effective and easy to read. It also enables easy access to 3rd party programs to extract comments out of code (Doxygen)
Admin
Not necessarily... there are developers out there who use languages other than C#. I like C# myself, but I must say it is one of the most over-evangelized languages out there.
Admin
The comments are not a WTF because .NET only makes sense if you use Visual Studio.
Admin
Hillaaarious! This is maybe better than the True/False/FileNotFound WTF.
It is stunning that the coder did not bother to test is his "algofithm" returns at least closely good values. I still havent found a single input with even close correct result.
My googles! They dont help! My eyeeees
Admin
It seems that one assumption of the code was that a/b = (a+c)/(b+c). Math is hard and he should have simply converted the values to string first. By the way, what is wrong with dividing 0 by non-zero?
Admin
No, the real WTF as usual are the article comments.
There is another new fangled thing that's called a dictionary. You may be interested in getting one. The real WTF is "divider" instead of "divisor" as was pointed out before.
Captcha: blind, sorry, bling. Oh the irony.
Admin
I think this comment line is particularly telling:
/// <returns></returns>
Obviously the coder himself couldn't say WTF is returned.
-Harrow.
Admin
The only thing missing is a call to containsNotEqualBackwards(), to confirm the variables at the end there.
Admin
Admin
It is for sufficiently small values of c, but even after replacing 10 by 10^-10 you don't get the correct answer. Using the de facto standard test of 10/2, the result returned by the code tends to 1.8 as c -> 0.
Admin
You can say dividend/divisor when speaking about Euclydian division and numerator/denominator when speaking about a fraction. See Wikipedia definition for all tis stuff.
But this Division by 0 is trully a WTF. Not only the resulult is always false, but when it invents the mathematical concept that dividing by 0 is determined and not null and included in Q (all real number that can be represented as X/Y, X & Y being integers).
Admin
You just have to love how the code snippet never checks wether the dividend or divider actually ARE zero.
Admin
Forget Programming 101, he needs to go back to Pre-Algebra. (His code, although horrible for the eyes, is... correct... (For Programming 101) Now if you will excuse me, I need to flush what I just saw out of my system.)
Admin
WTF? "= 2" is "<<= 1". "= 4" is "<<= 2".
Admin
How can you unread what you have read?
Please, tell me, since I follow this site I think I'm learning how to do things the bad way and I doubt that I can do them right from now on :`(
Heeeeeeeelp!!!!
Admin
0.0000000000000(insert more zeros here if required)0000001 != 0, but dividing by the former might still cause a division error. You'd probably get an overflow (+Inf or -Inf) rather than division by zero, but it's an error nonetheless.
Admin
Just looked closer, and for the case where dividend is greater than divider, this simplifies (excluding that special case in the middle, I'm not sure what that is trying to catch) to (2*dividend - divider + c)/(dividend +c), so you're not actually dividing by the divider at all.
Admin
Admin
OK, so at first glance it looks like he's using a very clever way to deal with the problem of dividing by values very close to zero. These are very easy values to get with innocuous-looking math, e.g. 40.0 / 4000.0 - 0.01 = -2.0837010502455788341080733516719192266464233398438e-19.
The problem is that for sufficiently small values of x, (x != 0.0) is true, but (1000.0 / x) will result in an error (specifically an overflow). I suppose the math implementation might also try to denormalize the divisor before division and end up with zero, which will result in a different error (division by zero).
If you instead do the check (divisor + 10 == 10) then you effectively truncate the divisor to zero if it is less than epsilon * 2 ^ (log2(10) - 51). Addition with doubles starts by shifting the mantissa of the lower-exponent value to match the higher-exponent value, which in the case of values smaller than 2^-51 * (higher-exponent-value) will turn the lower-exponent value into zero. If your floating point implementation has more or less than 51 bits in its mantissa then adjust accordingly.
To use the example above:
(40.0 / 4000.0 - 0.01) != 0.0
but
(40.0 / 4000.0 - 0.01) + 10.0 == 10.0
(at least on an i686 machine with GCC 4.1).
Unfortunately it seems that he's not doing anything near that smart...
Admin
Admin
That's just painful.
My brain is bleeding.
Admin
Admin
Results: running this code for both values being -10000 to 10000, excluding numerator / denominator, and excluding numerator / 0, these are the only correct results:
-2040 / -850 = 2.4 -2040 / 4920 = -0.414634146341463 -850 / -2040 = 0.416666666666667 -350 / -150 = 2.33333333333333 -350 / 840 = -0.416666666666667 -150 / -350 = 0.428571428571429 -60 / -30 = 2 -60 / 140 = -0.428571428571429 -30 / -60 = 0.5 -10 / 20 = -0.5 20 / -10 = -2 140 / -60 = -2.33333333333333 840 / -350 = -2.4 4920 / -2040 = -2.41176470588235
Admin
The code is insane, but the terminology is not completely wrong: dividend does mean 'quantity to be divided'.
A coworker of mine does worse though: In some reports, a division by zero is represented by 'fifty', in text!
Admin
Gah, I hate seeing crap like this. If you are about to divide by zero, things are already terribly wrong. There is no appropriate answer to a question that makes no sense.
If you are about to divide by zero, this indicates that you are in some kind of exceptional case, which is going to require different handling. YOU SHOULD HAVE IDENTIFIED THIS SPECIAL CASE LONG AGO, not at the moment before you are about to do the division. I don't care what domain you're working in -- a special divide function with divide-by-zero protection is just freaking dumb.
"My arm hurts when I do this!" Well, don't DO that then.
Admin
No, it can't. Unless, by "easily", you mean, "incorrectly".
Admin
Does this mean that another Martian lander is going to be lost?
Admin
Wow...this can't be true. No, seriously, it just can't. I know that some programmers are retards but DAMN! I only hope that this one doesn't go to teaching and pass this crap on to the kids. Oh the horror!
MIGRAINE!!! Must take Advil NOW!
CAPTCHA: dubya (fitting, isn't it?)
Admin
сабж
Admin
If by "epsilon" you mean "one", or by "51" you mean zero, then yes.
Admin
Dividend and Divisor are standard though old-fashioned terminology.
And for the English guy, well, divide by zero freaks turn up all the time.
However, IEEE floating point has the concept of a NaN (Not A Number) which is produced by various invalid operations. I suppose that's what Anderson was trying to do, but it's hardly a great breakthrough and probably too tricky for younger students.
Admin
The suffix is not always "-endum" and it is not just a fixed "special suffix" - it is the gerundive (see http://en.wikipedia.org/wiki/Gerundive) and the exact form depends on the conjugation of the verb, the genus, the grammatical number etc. popular examples: "ceterum censeo carthaginem delendam esse" or "quod erat demonstrandum" etc.
Otherwise, I concur :o)
Admin
Maybe the programmer was a untie-er not a divisor.
Admin
Ha ha! Another WTF comment par excellence. If divisor's absolute value is less than 10, then the addition will likely truncate a part of its mantissa (which happens to be 52 bits and not 51 bits wide for "double"s) in the addition. This is what the formula is intended to express. Your "corrections", OTOH, don't make any sense whatsoever.
There is one caveat: By default, x86 processors use 80-bit floats internally and only perform conversions to IEEE single and double precision floats when asked to do so. Therefore, 10 + x may be considered not equal to 10 even if x is less than 10 * 2^(-52) as long as the result of the addition is kept in a floating-point register and not explicitely rounded. The joys of floating-point arithmetic... in Java, this could be avoided with the strictfp keyword. In this case, it would force 10 + x to be rounded to double precision before the comparison, so e.g.
public static strictfp boolean truncateTest() { double x = 1e-16; return 10 + x == 10; }
would return true on all platforms.
Here's some output from Hugs which uses doubles by default and obviously rounds intermediate results:
Hugs> (10 + 1e-13) - 10 9.9475983006414e-014 Hugs> (10 + 1e-14) - 10 1.06581410364015e-014 Hugs> (10 + 1e-15) - 10 1.77635683940025e-015 Hugs> (10 + 1e-16) - 10 0.0
Admin
I'm with Sgt. Preston, though I credit the Utah Public Schools, not Canada.
"Dividend" for "That which is Divided", was standard in my day... and according to the dictionary, it still is.
(Admittedly, using "divider" rather than "divisor" is non-standard, but faulty memory suffices to explain it - and at the level of English rather than Jargon it's correct.)
The Real WTF is having to use BBCode. There's already an absolutely standard system for formatting text and inserting links, that our browsers and this site already implement. We call it "HTML".
Admin
Just tossing this out there: divisor/dividend are also standard terms (not divider, though).
Admin
The use of BBCode has one rather nice advantage: You don't have to worry about sanitizing HTML. If you just disallow ALL HTML and make people stick to a small set of explicitly-defined BBCode tags, you're much safer.
As with anything else that needs to be sanitized, you don't want to specify what you don't want...You want to specify what you do want and then implicitly deny everything else. Then your ass is covered. ;)
Admin
// Summary: // shifts all windows // // Params: // processName: Name of Process that owns the windows //
WOW a much better comment because it is easier to humanly read.
Admin
O - M - G !!!!!
Admin
Admin
No, thats a myth. In most compilers its the opposite. The checks usually get optimized by the compiler, while exceptions are somewhat costly (for instance you have to create an object, and there is very little optimization done as exceptions are supposed to rarely occur).
Admin
Holy cow. The WTF of this article fades to nothing compared with that of James Anderson.
Admin
Don't know in which universe you checked, but when I was in school, we called those "Dividend" and "Divisor", which would actually be the correct terms for the two operands of a division; "numerator" and "denominator" are used for a fraction ("Bruch"), and the correct German words are "Zähler" and "Nenner".
Admin
And indeed there was a recent <script> incident on this very site that demonstrated precisely why this is desirable.
Admin
I didn't even know it's possible to ++ floating points :)
Admin
Thanks. In a lot of these WTFs you can see what they were trying to do. In this case I was really struggling to see what he was trying to achieve.
An excellent combination of bad programming and bad maths.
Admin
Admin
System.out.println(5.0 / 0.0); throws DivisionByZero System.out.println(0.0 / 0.0); throws DivisionByZero
That is division by float/double throws, division by integers results in nan/infinity. I can only guess why.