Joined: Sun Oct 17, 2004 3:11 am Posts: 6822 Location: College Station, TX, USA Gender: Male
I have no idea why this amuses me so much, but anyway...
In Java there is a defined constant value known as NaN which when assigned to a variable signifies that it is "not a number." The use for this comes up when you're dealing with floating point, but this is all irrelevant and doesn't make much sense anyway.
What I'm getting at is that at some point it may be necessary to test for a value of NaN (error checking is a good example here). Now, you can be all boring and see if x == Math.NaN resolves to true. And sure, doing that will make your code clear and easy to understand.
However, any sadistic programmer like me loves to make things difficult for others because it validates our pathetic lives. Therefore, I prefer to take advantage of a little known property of our friend NaN. It is the only value for which an identifier becomes unequal to itself. Thus, in order to test for NaN, you can check if x != x resolves to true.
I consider this a much more interesting and confusing way to do things and thus highly recommend it. There's nothing I like more than spitting in the face of the rules of math.
Joined: Sun Oct 17, 2004 3:11 am Posts: 6822 Location: College Station, TX, USA Gender: Male
Speaking of funny things in Java, I love this quote from The Java Programming Language, Fourth Edition.
Quote:
Enum is actually a generic class defined as Enum<T extends Enum<T>>. This circular definition is probably the most confounding generic type definition you are likely to encounter. We're assured by the type theorists that this is quite valid and significant, and that we should simply not think about it too much, for which we are grateful.
Joined: Sun Oct 17, 2004 3:11 am Posts: 6822 Location: College Station, TX, USA Gender: Male
I need to post a correction to my initial post. Because NaN is the only value that doesn't equal itself, you can't simply do an equality check because...
x == Float.NaN and x == Double.NaN always equal false and x != Float.NaN and x != Double.NaN always equal true.
Therefore you use Float.isNaN(float) or Double.isNaN(double) which return a boolean value.
Or, of course, you can see if x != x equals true.
And speaking of funny quotes from that book, this one is unintentionally hilarious when taken out of context:
Joined: Wed Oct 20, 2004 8:35 pm Posts: 8770 Location: flap flap flap hey no fair i made my saving throw
fuck I haven't used Java in so long. I almost miss it
_________________ New Age bullshit is just a bunch of homo shit that some rich fuck came up with to scam people. It's exactly the same as scientology and every other religion: fake.
Users browsing this forum: No registered users and 12 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum