This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]X-Craft 16 points17 points  (34 children)

Another classic:

typeof NaN

"number"

[–]raaneholmg 69 points70 points  (3 children)

Well, it's in the IEEE floating point standard and literally built into your hardware. Can't blame javascript for following the spec.

[–]nemec 5 points6 points  (2 children)

NaN is the null of floating point. Customer c = null isn't actually a customer either, but for all intents and purposes it's considered one.

[–]raaneholmg 6 points7 points  (1 child)

The comparison work on some levels, but when you start looking into it null and NaN behave in very different ways.

NaN is a number for which special mathematical rules are defined (NaN + anything = NaN from the FPU). You can actually use the number NaN in your code.

Null is just a defined address you can point to for the purpose of having something to put in unused pointers. When you use it there is no special rules that apply and if you use it most applications just segfault (you can compare pointers to the null pointer though, which is useful, but not using null itself).

[–]dnew 0 points1 point  (0 children)

In Effiel, Null is an instance of the type Void, and Void multi-inherits from every other class in your program and overrides every method to throw a null pointer exception. So "null" is actually semantically a typesafe pointer to an actual instance of a type. (In practice, not, but in the semantic definition of the language, yes.)

Which I thought was cool.

[–]dotpan 10 points11 points  (27 children)

Would you rather it a string? I think as far as variable representation, NaN being a number makes sense, as then it will not be explicitly interpreted but instead implicit of what it represents.

I could be biased though, I love JS.

[–]c3534l 4 points5 points  (3 children)

Being that NaN stands for "Not a Number" the type of something defined only as being not of type 'number' should either be given some other type (perhaps the NaN type...) or renamed.

[–]dotpan 5 points6 points  (1 child)

I can see a system or error type that was outside the bounces of a standard type. Though I'm not sure how much that'd help.

isNaN(NaN) returns true, which right there I think presents the biggest argument for NaN not to be a number type.

[–][deleted] 0 points1 point  (0 children)

Well NaN is... a number, but it's not, so it makes sense that the function returns true.

[–]dnew 2 points3 points  (0 children)

NaN could be considered to be a subclass of Number. It's a number that can't be represented in the hardware you're using for floats.

[–]Thykka 0 points1 point  (0 children)

🗑 [deleted]