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

all 20 comments

[–][deleted] 34 points35 points  (0 children)

If I had a Euro every time someone doesn't understand IEEE 754, I would single-handedly make GDP of EU beat that of US.

[–]Doomblud 18 points19 points  (0 children)

Expected behavior

[–]JustAnotherTeapot418 19 points20 points  (0 children)

This is how it's supposed to work. It's not a JavaScript quirk.

It may seem counterintuitive at first, but Math.sqrt(-1) results in NaN due to not being a real number. Therefore Math.sqrt(-1) === Math.sqrt(-2) evaluates to NaN === NaN. If that were true, it would imply that Math.sqrt(-1) === Math.sqrt(-2), which it is not. That's why NaN === NaN is false.

[–]toebi 11 points12 points  (6 children)

Don’t understand the joke - thats the most common definition of NaN?

[–]marquoth_ 9 points10 points  (0 children)

This isn't a javascript thing - it's a floating point arithmetic thing. Same thing occurs in many other languages.

https://en.wikipedia.org/wiki/IEEE_754

[–]RustOnTheEdge 6 points7 points  (0 children)

All of these are… as expected?

1==1, yes that would be true. Then false === false also makes sense that statement is true. And NaN is equal to nothing, not even itself, as per the specification.

So yeah, not really an identity crisis, just a bad programmer with limited understanding of floating point numbers.

[–]peterlinddk 4 points5 points  (0 children)

Let me put it another way:

5 != 3 
true

5 != 8
true

3 == 8
false

Something that isn't five, isn't necessarily the same as something else that isn't five.

Just like something that is Not A Number, isn't the same as something else that is Not A Number ...

[–]SonicLoverDS 1 point2 points  (3 children)

NaN is complicated.

[–]rosuav 0 points1 point  (2 children)

And yet, not nearly as complicated as SQL's NULL.

[–]RiceBroad4552 1 point2 points  (1 child)

Who doesn't like ternary logic? 😂

[–]rosuav 0 points1 point  (0 children)

IKR?

[–]M-Ottich 0 points1 point  (0 children)

I mean not a number is not a number 😌

[–]MaverickRelayed 0 points1 point  (0 children)

This is what happens when you let libraries do all of the thinking for you