# use decimal

Brendan Eich brendan at mozilla.org
Thu Sep 18 12:54:32 PDT 2008

```On Sep 18, 2008, at 1:06 AM, Mark S. Miller wrote:

> "apart from somthing like significance" is a huge new set of
> exceptions. A large enough set that we can no longer understand ===
> as approximating operational equivalence. If instead we understand
> === to be asking whether two operands are cohorts, and we define
> cohorts to be those numeric values that exactly represent a given
> real number, then
> 1) -0 vs 0 is no longer irregular

0 and -0 are in different cohorts, thanks to MFC for making this
clear (it seemed implied by past discussion of 1.5m, 1.50m, 1.500m,
etc. all being in the same cohort -- no sign difference --but it's
good to have clarity).

> 2) We can explain why 1.5 === 1.5m === 1.5000m

That's explained by cohorts in 754r.

> 3) We can explain why 1.1 !== 1.1m.

The alternative to real number projection is conversion with
rounding, which is what people will actually run into when mixing
modes. (I smell lots of bugs there, btw, but that's a separate topic.)

The point here is that, for all practical meanings of "operational"
that I can think of, and excluding the -0 vs. 0 issue (or non-issue
-- it's been that way since ES1 and numerical analysts prefer it for
subtle reasons), defining decimal and binary floating point
equivalence based on projection idealizes away from the concrete
operational semantics, as Maciej pointed out with 1.5m/10 vs. 1.5/10.

Real numbers are wonderful (I mean this sincerely, in a Mathematical
sense), but they're neither well-supported in ES or most languages
and all hardware, nor well-understood by most programmers (IMHO).

If we did make typeof 1.1m == "number" then I suspect we would break
some current code that "knows" about IEEE-754 double (precision
limits, e.g.).

The safest course still seems to me to be typeof 1.1m == "decimal".

/be
```