use decimal
Brendan Eich
brendan at mozilla.org
Wed Sep 17 19:35:45 PDT 2008
On Sep 17, 2008, at 10:13 PM, Mark S. Miller wrote:
> 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.
>
> Brendan, please correct me if I misrepresent your argument.
>
> 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.
Here is what I wrote:
> Without "use decimal", typeof 1.1m must not be "number" to preserve
> this same invariant [that a === b <=> typeof a == typeof b && a
> == b].
> Otherwise (without "use decimal") 1.5m == 1.5
> but 1.1m != 1.1, so without making typeof 1.5m != typeof 1.1m, we
> cannot have typeof 1.5m == "number".
Please expand your syllogistic reasoning:
Major premise #1: a == b
Minor premise #1: typeof a == typeof b
Conclusion #1: a === b
(you can switch == and === above -- the implication goes both ways
and choice of == or === for typeof a OP typeof b does not matter
since typeof's result is of string type.)
Major premise #2: 1.5m == 1.5
Minor premise #2: typeof 1.5m == "number" (your position, IIUC)
Conclusion #2: 1.5m === 1.5
(by Conclusion #1 and ES1-3 (which define typeof 1.5 == "number"))
Counter-example: 1.1m != 1.1
but typeof 1.1m == typeof 1.1 in your proposal (again IIUC)
This is a for-all problem. If there exists some double value x such
that, for the decimal form y spelled literally using the same digits
but with an 'm' suffix, x != y, yet typeof x == typeof y, then typeof
must depend on whether its operand value converts losslessly to
decimal from double and double from decimal.
This is broken -- typeof should depend on type, not value.
Hence my position (Waldemar's too) that typeof 1.1m == typeof 1.5m &&
typeof 1.1m == "decimal".
> 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.
=== does approximate operational equivalence apart from significance.
Right? (I'm asking because I could be wrong, not rhetorically!)
> 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.
A lot more.
Two wrongs don't make a right.
One exception to the rule is better than two, or 2^53 or larger.
/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080917/a41d4321/attachment.html
More information about the Es-discuss
mailing list