# Es-discuss - several decimal discussions

Mark S. Miller erights at google.com
Sun Aug 24 15:14:52 PDT 2008

```On Sun, Aug 24, 2008 at 1:43 PM, liorean <liorean at gmail.com> wrote:
> And I'd argue that you're wrong there. NaN isn't a single value.

Arithmetically, perhaps not. == and === already represent the
arithmetic semantics of NaN and -0.

Computationally, all NaNs are not observably distinguishable in ES3
and, AFAIK, in 4/4 browsers. -0 and 0 are observably distinguishable
in ES3 and in 4/4 browsers.

Finally, even if some NaNs are observably distinguishable from other
NaNs (though this is disallowed by ES3 for EcmaScript code), that by
itself doesn't justify:

const x = NaN;
x === x // yields false

Surely x holds whatever value x holds. How can this value not be the
same as itself? For an arithmetic equality primitive, I accept that
this peculiar non-reflexivity may be a desirable property; or at least
that this is the mistake that has become the permanent standard among
numerics. However, abstractions like memoizers need to reason about
computational equivalence at the level of the programming language
semantics. Let's not allow the distinct needs of reasoning about
arithmetic corrupt our abilities to reason reliably about computation.

Object.eq(x, x) // yields true

since the value of x is whatever it is.

> But NaN represents *any arbitrary value* in the
> infinite set of values that cannot be converted into numbers, not a
> *specific value* in that set.

Then whatever set of arithmetic values is represented by the
computational value in x, x is a computational value that represents
that set of arithmetic values.

> In other words, NaN should never equal NaN using any equality
> operator, unless you build your number system so that NaNs remember
> what specific value they were converted from and do an object
> comparison instead of number comparison for those. Which is not the
> case for ECMAScript.

Object.eq() is not an operator of the number system. Between two
numbers, == and === are already adequate for numeric "equality".

--
Cheers,
--MarkM
```

More information about the Es-discuss mailing list