Initial comments on Kona draft

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Fri Nov 14 22:43:51 PST 2008


Sam Ruby wrote:
> Waldemar Horwat wrote:
> 
>> 11.9.3:  The contagion here is from Number to Decimal.  This is
>> inconsistent with +, -, *, etc., where the contagion is from Decimal
>> to Number.  It should be the same for all arithmetic operations.
> 
> The contagion should consistently be from Number to Decimal.  I
> distinctly remember making this change this time, but double checking
> what I sent to Pratap, it seems like the version of the document that I
> sent him did not include this change.  *sigh*
> 
> To be clear, step 5 in the binary operators should read "5. If
> Type(Result(2)) is Decimal or Type(Result(4)) is Decimal, then",
> substituting "or" for "and" in the expression.

(I assume we are talking about sections 11.5, 11.6.1, and 11.6.2.)

That doesn't work. Step 5a in each of these algorithms assumes that
both arguments are decimal values. You need something like:

5. If Type(Result(2)) is Decimal or Type(Result(4)) is Decimal, then
     a. Call ToDecimal(Result(2)).
     b. Call ToDecimal(Result(4)).
     c. Perform <whatever operation> as defined in IEEE 754-2008 with
        arguments Result(5a) and Result(5b).
     d. Return Result(5c).

Of course ToDecimal must be defined as the identity function on
decimal values.

However, it is not clear to me that the resulting behaviour is
consistent in the case of binary '+' (section 11.6.1):
string + number  and number  + string return a string, but
string + decimal and decimal + string would return a decimal.

The *least inconsistent* option that I can see (that is still
compatible with ES3) would be to move step 5 as defined above
just before the call to ToNumber in step 9.


Another issue I've just spotted is that Decimal *objects* do not
behave analogously to Number objects: ToNumber calls ToPrimitive
which does unwrapping, but the checks for decimal arguments only
check that the Type is Decimal, and do not unwrap. This makes Decimal
objects even more useless than the other wrapper objects.


Incidentally, there is no such thing as an "addition method",
"subtraction method", etc. in IEEE 754-2008. "Method" here is an
ECMAScript term.

-- 
David-Sarah Hopwood


More information about the Es-discuss mailing list