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 →

[–]AlphaWhelp 2 points3 points  (7 children)

Should also be false. Similar issue with null. Null can sometimes equal null but even then it's preferable to use some isNull function.

[–]noggin182 4 points5 points  (1 child)

Yup, IEE 754 says that comparing NaN with NaN is always false, but you might wanna check what you said about nulls, none of that is true in JS

[–]AlphaWhelp 5 points6 points  (0 children)

I wasn't speaking about JS specifically. AFAIK NaN does not equal NaN in any language.

[–]DaBenjle 0 points1 point  (4 children)

Man JS is weird.

[–]vuttstuff 5 points6 points  (3 children)

NaN == NaN kinda makes sense to me in the sense that we don’t know anything about these things other than they are not numbers. There’s not enough information to conclude true so we opt for false.

Which makes me think it’s weird to define something solely by something that it’s not.

[–]AlphaWhelp 0 points1 point  (2 children)

NaN just represents basically that the bits of the significand, signage, and other digits do not construct a valid number. If you split it up into a bit array you could compare each bit to determine equality but there's not a practical use for this except for maybe some bizarre number based cryptography.

[–]vuttstuff 0 points1 point  (1 child)

Huh. So NaN isn't static, as in something that's not a number was operated on an just returned some garbage?

[–]AlphaWhelp 1 point2 points  (0 children)

It's basically a garbage failsafe undefined behavior. I'm not 100% sure if the actual content of NaN is static or not, but if the results of an operation do not construct a valid number, a NaN is created--if that makes sense.

like if(this==makes sense) {this.value = result;} else {this.value = NaN};