- 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
If there isn't, there should be because that isn't easy to do. You have to try pretty hard.
A small annoyance in the grand scheme but, I hate when people don't use a ternary for these simple if...else conditions.
Admin
This looks like Java to me.
Admin
And for those who don't know, that means that the long type has 64 bits, regardless of the machine.
Oh, and C++ doesn't throw exceptions on division by zero. The behaviour is implementation-defined: POSIX-based machines will cause a SIGFLT (I think), Windows-based will throw a /0 SEH exception (which is not the same as a C++ exception).
Admin
I think we need to start a new sourceforge project, libwtf
It would be a collection (or perhaps, a collection for each submitted language) of the best entries found here.
If possible, it should make the compiler (vm, etc...) explode.
The CVS would need to be set up to not allow edits, we don't want people 'fixing' the code!
Admin
C++ on windows can be convinced to use standard C++ exceptions... I forget how at the moment, but it's not too difficult.
Admin
Hmm... I think I'm growing senile. Java integer division rounds towards zero as well. I was sure it rounded down though so that (-7)/3 would be -3 in java. Maybe I'm getting confused with Apple II Basic or something [:S]
Admin
Nice monkey. First time I've seen that.
Admin
Is "wanker" passe' now?
Admin
Is that like the non-trivial zeros of the Riemann Zeta Function?
Admin
Yea, but it took years for anyone to notice, because that was back in the NT 4 days, and servers never went for a month without a reboot.
Admin
That has nothing to do with this wtf, which is written in Java. Every JVM is required to use 32 bits for int, and 64 bits for long. There's no guesswork for platform the code will be run on.
Admin
Rhetorics? Is that that new feature they are putting in C# 2.0?
Admin
Ytram, you're the reason I keep coming back to this site. It's not just your humor either. It's that sweet sweet pizza-making man-love.
Admin
In Java and C#, int is defined as a 32-bit integer while long is defined as a 64-bit integer. The actual processor is irrelvant.
Admin
Just tested it in Java as well, and it performs the same way:
public static void main(String [] args)
{
System.out.println("Positive: " + 5/2);
System.out.println("Negative: " + -5/2);
System.out.println("Straight cast of negative double(-2.3): " + (int)-2.3);
}
Had an output of:
Positive: 2
Negative: -2
Straight cast of negative double(-2.3): -2
So despite your Capt. Obvious remark about the WTF actually being written in Java, the quotient from integer division is still directed towards zero.
Admin
Yep. It was 49.7 days, actually, and it went unnoticed for about 4 years.
Old news article on it: http://news.com.com/2100-1040-222391.html?legacy=cnet
It had to do with the Windows Virtual Machine Manager and the Get_System_Time function. One of the things this function did was to load the EAX register with the number of milliseconds since the machine was started. EAX is a 32 bit register. When it looped, the time would reset to zero, and anything calling get_system_time would likely freak out.
It only affected 95 and 98 First edition, actually. NT4 was actually not affected.
Admin
Right.
I love this line. In C, C++, and possibly other C-derived languages, integer overflow on signed values results in undefined behaviour. On a twos-complement machine (e.g. x86), applying negation to the most negative value results in an overflow. Easier? Easier to WTF!
There is also the overflow of long to int that others have mentioned.
Sincerely,
Gene Wirchenko
Admin
Yeah, I like pizza too!
I'm just assuming this is a typo.
Admin
You lack ambition, my friend.
It should do its damnedest to frag the HARDWARE!
Admin
Ohh ohh! I have some suggestions:
Admin
Too easy.
When I was taking my diploma:
1) Some C++ code caused the compiler to throw an internal error. I had forgotten a pair of "()" after two method names in one line.
2) One extra period in a COBOL program caused the compiler to crash. It simply terminated with no error message. Because of this, there was no listing generated. It is good that I had a fair idea of what the error might be. Without the period, the program worked perfectly.
3) The same compiler blew up on another program of mine. I had turned on the checking options (overflow, unitialised variable, and array bounds). The uninitialised variable use check was incompatible with the COBOL report writer, and my code failed to work. Without the option set, my code worked fine.
Anyone else who has been in the industry for a while probably has similar stories.
Sincerely,
Gene Wirchenko
Admin
I bet the usage of this method looked something like this:
<font size="1">long millidiff = System.getCurrentTimeMillis() - startTime;
System.out.println("This took: " + convertToHours(millidiff) + ":"
+ convertToMinutes(millidiff) + ":"
+ convertToSeconds(millidiff));</font>
Admin
Similar in terms of the specific languages in use at the time or similar in terms of being absent-minded as a result of being semi-ignorant of the language you're working with? If the latter, then anyone who has every learned a new language has similar stories, not just the dinosaurs.
Admin
Nevermind, that wouldn't quite work.. if it took more than 59 minutes, he'd see something like "This took: 2:143:16"
Admin
Before anyone lashes me with my own whip, I know, piss poor grammar.
Admin
I really want a T-Shirt that says
Admin
This is the sort of nonsense up with which I shall not put!
Admin
WTF, I just don't get it... don't these people know, what the stack is made for?
It should of course be
static int milli_so_far = 0;
int convertToMinutes (long milliDiff) {
milli_so_far += 1;
if (milli_so_far == 60000) {
milli_so_far = 0;
return convertToMinutes (milliDiff - 1) + 1;
}
return convertToMinutes (milliDiff - 1);
}
Disclaimer: Please note, that this method is not thread-safe. If you plan to use it in a threaded application, please don't blame be if it doesn't work!!
Admin
Oops, forgot to add the stopping condition...
static int milli_so_far = 0;
int convertToMinutes (long milliDiff) {
if (milliDiff == 0)
return 0;
milli_so_far += 1;
if (milli_so_far == 60000) {
milli_so_far = 0;
return convertToMinutes (milliDiff - 1) + 1;
}
return convertToMinutes (milliDiff - 1);
}
Admin
Maybe he was paid by the line.
Admin
May as well go surf naked, for all the protection offered in the code.
pi
^--- If a non-Y-mouse can do it, so can you!
Admin
On x86 machines, divide by zero generates a hardware exception (interrupt 0).
Admin
ps. Don't bother replying if all you want to say is you have had a Windows server last more than a week; I have no prizes to give away at this time.
Admin
Similar in terms of compilers that blow up on odd input. One extra period crashing a compiler means the compiler is much frailer than it ought to be. (That particular compiler was sensitive to errors in the FD/SD/RD areas.) This is, of course, rather easy when you are still learning what unodd is.
Sincerely,
Gene Wirchenko
Admin
Sorry. The keys are like right next to each other.
Today's response is brought to you by this quote from bash.org
Admin
or -0.01715 minutes.
Jeff
Admin
but we're dividing by 60k, not zero.
Jeff
Admin
Not to be confused with the trivial ones. [:P]
Admin
2 X WTF
Admin
You hitting the "Quote" button AND the "Post" button?
Admin
I see. I happened upon the scene when frailty of compilers wasn't such an issue. Unfortunately, frailty of knowledge on the other hand, which plagues all who try a new language, will be with us forever. In the end, it's the same struggle.
Admin
Yeah... zero's purportedly especially dangerous when you divide it by anything... 8-)
Admin
> Except integer division doesn't round, it truncates, and will therefore always go towards zero anyways.
Depends on the "programming language"...
Admin
He could do a case
switch(IsTrue(milliDiff==0)){
case true: //do nothing;
break;
case false: //flip to positve
break;
case else: //return file not found.
break;
}
JC
Admin
You must have slept through middschool then! Just try for yourself how to do long division with a negative dividend! See, it's already confusing to a human, let alone a much less intelligent computer!
And special casing 0 is actually a good thing. What's the point of the error prone division, when the result is 0 anyway? Always remember the lessons the original Intel Pentium (codenamed something around i585.99) taught us!
Admin
I guess that might had been more of a mathematician's joke than a programmer's. The "trivial" zeros of the Zeta function occur for all negative even integer inputs. The non-trivial zeros occur for certain complex numbers and have a very close relation to the prime counting function. The Riemann hypothesis asserts that all non-trivial zeros have real part of one-half. This has never been proven and is one of the last problems from Hilbert's list that has yet to be resolved.
Admin
Next thing you know, samples from this site will crop up all over tedbilly's code.
Admin
The real wtf here is that this subhuman programmer is using a ridiculous, space-wasting brace style.
Admin
If they are worried about milliDiff being negative, the solution is (in Java) the following.
minutesDiff = Math.abs( time2 - time1 ) / 60000;
Since there are no comments documenting what the function should output (another WTF), the above statement is an acceptable replacement for this function.
Admin
For all negative even integers, no! Those are indeed trivial...