Es-discuss - several decimal discussions

Sam Ruby rubys at intertwingly.net
Mon Aug 25 14:03:23 PDT 2008


On Mon, Aug 25, 2008 at 9:45 AM, Mark S. Miller <erights at google.com> wrote:
> On Sun, Aug 24, 2008 at 11:20 PM, Brendan Eich <brendan at mozilla.org> wrote:
>> Yes, this is gross. I'm in favor of Object.identical and Object.hashcode,
>
> I don't care if Object.eq is named Object.identical. Other than
> spelling, does your Object.identical differ from Object.eq? If not,
> then I think we're in agreement.
>
>> maybe even in ES3.1 (I should get my act together and help spec 'em). Just
>> not particularly on account of Decimal, even with equated cohort members. I
>> still agree with Sam. And as always,"hard cases make bad law".
>
> What is it you and Sam are agreeing about? I lost track.
>
> I like the point about bad law. Numerics are definitely a hard case.

Here's the current output from my current branch of SpiderMonkey:

js> /* Hopefully, we all agree on these */
js> 1.0m == 1.0m
true
js> 1.0m == new Decimal("1.0")
true
js> 1.0m == Decimal("1.0")
true
js> 1.0m == 1.0.toDecimal()
true
js>
js> /* And these too... */
js> 1.0m == 1.00m
true
js> 1.0m == 1.0
true
js> 1.0m == "1.0"
true
js>
js> /* Conversion is exact, up to the number of digits you specify */
js> 1.1.toDecimal()
1.100000000000000088817841970012523
js> 1.1.toDecimal(2)
1.10
js> 1.1m - 1.1
-8.8817841970012523E-17
js> 1.1m == 1.1
false
js>
js> /* Non-strict equals doesn't care about precision */
js> 1.0m == 1.0m
true
js> 1.0m == 1.00m
true
js> 1.0m == 1.0
true
js> 1.0m == "1.000"
true
js>
js> /* You can mix things up */
js> Decimal.add(1.1,1.1m)
2.200000000000000088817841970012523
js> 1.2m - 1.1m
0.1
js> 1.2m - 1.1
0.099999999999999911182158029987477
js> 1.2 - 1.1
0.09999999999999987
js> 1.1 > 1.1m
true
js>
js> /* Things we agree on for strictly equals */
js> 1.0m === 1.0m
true
js> 1.0m === 1.0
false
js>
js> /* Something that a case could be made for either way */
js> 1.00m === 1.0m
true
js>
js> /* In any case, there always is this to fall back on */
js> Decimal.compareTotal(1.0m, 1.0m) == 0
true
js> Decimal.compareTotal(1.00m, 1.0m) == 0
false
js>
js> /* Still open for discussion  */
js> typeof 1m
object

- Sam Ruby


More information about the Es-discuss mailing list