# use decimal

Mark S. Miller erights at google.com
Wed Sep 17 19:13:39 PDT 2008

```On Wed, Sep 17, 2008 at 6:50 PM, Maciej Stachowiak <mjs at apple.com> wrote:

>
>
> I agree that typeof 1.5m == typeof 1.1m. However, I do not agree that 1.1m
> == 1.1. These should be !=, since they represent distinct real numbers.
>
>
> It seems to me that Brendan said 1.1m != 1.1 and did not question this.
>

I took Brendan to be saying that

1) If typeof 1.1m were 'number' then we'd be obligated to have 1.1m == 1.1.

2) We want 1.1m != 1.1.

3) Therefore, typeof 1.1m must not be 'number'.

I disagree with #1 and thus #3.

>
> I do agree that 1.5m == 1.5, but only because they represent the same real
> number, not because they look the same. This extends the notion of cohort
> across the decimal/binary divide.
>
> -0, 0, -0m, 0m, 0.000m
>
> may all be computationally distinct values. (Is 0.00m distinct from 0m?) If
> they are, then they should therefore be distinguished by any
> Object.identical() and Object.indentityHash() operations. But they all
> represent the same real number, so they should be ==. If we agree that they
> should also all be typeof 'number', then they should also all be === and be
> considered generalized cohorts.
>
>
> Brendan's premise is that 1.5m has different operational behavior from 1.5
> and therefore it would be wrong to make them '==='. I tend to agree. Making
> '===' treat distinct values the same and then introducing a new
> Object.identical to tell the difference seems inelegant.
>

-0 has a different operational behavior than 0. Ok, we've got one weird one.
I could live with that as an exception to a general rule.

However, with the introduction of decimal, we've got cohorts galore. 1.1m
has a different operational behavior than 1.1000m, but we've agree they
should be ===. With the introduction of decimal, === no longer approximates
a test of operational equivalence, and we still need such a test.

>
>
>
> If typeof all these were 'number', then binary and decimal could share a
> single NaN, Infinity, and -Infinity. Only the remaining finite numeric
> values would be distinctly either binary or decimal.
>
> I agree with Sam and apparently Crock and everyone else that mixed mode
> should coerce to decimal. Or, at least, I have no objection to that
> position.
>
>
> If that is the case then 1.5m / 10.0 != 1.5 / 10.0, and thus it seems wrong
> for 1.5m and 1.5 to be '==='.
>

0/-0 != 0/0. Does it thus seem wrong that -0 === 0?

Well, yes, actually it does seem wrong to me, but we all accept that
particular wrongness. This is just more of the same.

>
> Were we to adopt this, then I think "use decimal" should condition only
> whether an unqualified numeric literal be interpreted as binary or decimal
> floating point. We should then have a suffix which means binary floating
> point, so you can say it explicitly. Nothing else about the numerics should
> be conditioned by the pragma.
>
>
> Perhaps that suffix could be 'f' as in C/C++.
>
>
I think that's better than 'd'. But it's confusing in a different way:
decimal floating point is still a floating point just as much as binary
floating point is. I have no letter to suggest.

--
Cheers,
--MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080917/1bb2a95e/attachment.html
```