Consistent decimal semantics

Mark S. Miller erights at google.com
Thu Sep 4 09:19:43 PDT 2008


On Thu, Sep 4, 2008 at 8:30 AM, Sam Ruby <rubys at intertwingly.net> wrote:
> In particular, does that imply the need for a wrapper class?

I think so. Given the new behaviors we all seem to have agreed on:
   typeof 1m === 'decimal' && !0m === true
then decimals act like their own new primitive type. We do the least
new damage to the language by having this work as parallel as possible
to the existing primitive type. This means a corresponding new wrapper
type. So I'll fill in my preferences at your ???s below.

> 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
> ???

false

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

false

> 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)
> ???

object

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

Thanks.


-- 
 Cheers,
 --MarkM


More information about the Es-discuss mailing list