What is bigger?

Started by
21 comments, last by Endurion 13 years, 1 month ago
Hello,
I was talking with my friend, when we actually met a question, what number is bigger - if NULL or NaN. We decided to post it here - to other fellow programmers. Don't take this question too seriously, we just want to hear opinions on this from other people (especially other programmers) here.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Advertisement
NULL is bigger cause NaN is not a number. NULL is neither a number but it doesn't matter cause it's name doesn't imply it and besides it is written in CAPS so it GOTTA BE BIGGA!
[size="2"]I like the Walrus best.
Comparing NULL and NaN doesn't work at all. What is biggest, my hat or your age?

Or if we look at it from another perspective NULL could be bigger because it's all in upper case and consists of more letters.
It depends on your perspective. NaN is of course not a number, but if you call (C++) std::max( NULL, NaN ), you it still to return a value. There was a recent discussion about this on the C++ google group: http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/a568c6009428b153/ae658a34f196de52#ae658a34f196de52

I wonder how other languages would deal with the expression (NaN < NULL).
The question doesn't make any sense.

But given that NaN is a floating value, and NULL is the literal 0, then any comparison will implicitly convert NULL to a float, and all comparisons against NaN are false (even NaN != NaN). So if you check if NULL > NaN, you'll get false. You'll also get false if you ask if NULL is smaller than NaN, or equal to it.

Your handy guide to NaN on your system:


#include <iostream>
#include <limits>

int main()
{
float NaN = std::numeric_limits<float>::quiet_NaN();
const char *answer;

answer = (NULL > NaN) ? "true" : "false";
std::cout << "NULL bigger than NaN : " << answer << '\n';
answer = (NULL < NaN) ? "true" : "false";
std::cout << "NULL smaller than NaN: " << answer << '\n';
answer = (NULL == NaN) ? "true" : "false";
std::cout << "NULL equal to NaN : " << answer << '\n';
answer = (NULL != NaN) ? "true" : "false";
std::cout << "NULL not equal to NaN: " << answer << '\n';
}
Why don't you guys just learn the usual goddamn routine.
Your question in highly dependent on platform. But close to everywhere nan will be biggest

On my current platform this:

writeln('Nil(0): ',sizeof(nil),'(',sizeof(0),')');
writeln('NaN: ', sizeof(nan));

writes:

Nil(0): 4(1)
NaN: 10
I think the whole exercise is meaningless; this is like comparing Chuck Norris with Vien Diesel, or pirates with ninjas, or cats with dogs, and so on.
Latest project: Sideways Racing on the iPad
Null... its 4 characters vs NaN's 3...
Gavin Coates
[size="1"]IT Engineer / Web Developer / Aviation Consultant
[size="1"][ Taxiway Alpha ] [ Personal Home Page ]
Already been said but:

NaN > NULL => false

NaN < NULL => false

NaN == NULL => false

Oh shit......




If we look at the hexadecimal memory, NULL is 0x00000000 while NaN is not. But if we take signed numbers into account, it may depend if it's a QNaN or SNaN.

Well, I haven't looked at the hex display, nor I care :P

On the other hand NULL is in CAPS!!!

In the x86 NULL * NaN = NaN, so NaN wins

On the second round, this time in the PS2, NULL * NaN = NULL, so NULL wins. I'm wondering who will make the fatality in round 3....

This topic is closed to new replies.

Advertisement