Consistent decimal semantics

Sam Ruby rubys at intertwingly.net
Thu Sep 4 08:30:46 PDT 2008


Brendan Eich wrote:
> On Sep 3, 2008, at 9:16 PM, Sam Ruby wrote:
> 
>> If typeof(0m) is "number", then !0m should be true.
>> If typeof(0m) is "object", then !0m should be false.
>> If typeof(0m) is "decimal", then we are free to decide what !0m should 
>> be.
>>
>> My preference is for typeof(0m) to be "decimal" and for !0m to be true.
> 
> That's my preference now too, but based on more than aesthetics.

Does that mean that the following need to be revisited?

http://intertwingly.net/stories/2008/08/29/estest.html#s11.4.3
http://intertwingly.net/stories/2008/08/29/estest.html#s11.8.6

In particular, does that imply the need for a wrapper class?  First, 
here's existing behavior:

js> 1 instanceof Number
false
js> Number(1) instanceof Number
false
js> new Number(1) instanceof Number
true

And those results correspond to:

js> typeof 0
number
js> typeof Number(1)
number
js> typeof new Number(1)
object

So, what should the following return (where I've filled in the few cases 
where I think the answer is obvious):

js> 1m instanceof Decimal
???
js> Decimal(1m) instanceof Decimal
???
js> new Decimal(1m) instanceof Decimal
true

And the corresponding typeof results:

js> typeof 1m
decimal
js> typeof Decimal(1m)
decimal
js> typeof new Decimal(1)
???

Whatever the consensus is, I'll update my SpiderMonkey branch to match 
and then will post the updated test results.

- Sam Ruby



More information about the Es-discuss mailing list