Home node.js why nan is not equal to nan?

why nan is not equal to nan?

Author

Date

Category

Why?


Answer 1, Authority 100%

Let’s try to look at the problem from the point of view of mathematics. As is known, Nan is a typical result for action like dividing infinity to infinity or zero on zero and other operations, the result of which from a mathematical point of view is not defined or does not make sense.
For example, from mathematics it is known that the logarithm of a negative number is not defined. That is, the next operation will have the result of NAN:

math.log (-5) // Nan

At the same time, if you try to perform such an operation: 0/0 It will also be Nan. In this case, it suggests that math.log (-5) and 0/0 are equal (in both cases we will get NaN). Obviously, it is not. Therefore, it is assumed that Nan is not even equal to himself.

(Moreover, be NaN is equal to yourself, then the help of non-good transformations could be concluded that 2 == 1)

in other words, Nan is not a specific value, but just a certain enough convenient abstraction, under which a variety of different meanings can hide, absolutely not equal to each other.

This paradox has a curious consequence: the ISNAN function is easy to implement this way:

Return Arg! == arg;

Answer 2, Authority 32%

Mozilla write about Nan so:

Description

Nan is a global object property.

The initial value of Nan This is not-a-number – the same thing that Number.nan . In modern browsers Nan it is immutable, only for reading a property. Even in cases when it is not, do not override it.

Using NaN in programs is quite rare. This value is returned in cases when it is not possible to calculate the F-AI object Math (math.sqrt (-1) ) or fails to fail the line conversion in the number (PARSEINT ("BLABLA") ).

comparison with nan

Equality operators (== and === ) cannot be used to compare the values โ€‹โ€‹with NaN. Instead, use the Number.isnan () or iSnan () .

nan === Nan; // False
Number.nan === Nan; // False
ISNAN (NAN); // True.
ISNAN (Number.nan); // True.

Answer 3, Authority 18%

Now in PHP checked in AS3 (choice
fell due to online compilers
At hand) And there Nan is Nan

oh well ๐Ÿ™‚ I am sure that it is there equals?

if (nan == nan) {
  Echo 'True';
}
ELSE {
  echo 'false';
}

or even so

var_dump (nan == nan); // Boolean False

In any jap nan == nan = & gt; false

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions