Revisiting Decimal (generic algorithms)
brendan at mozilla.com
Fri Jan 30 22:05:07 PST 2009
On Jan 18, 2009, at 4:48 PM, Brendan Eich wrote:
>> In any case, I think we first need to decide what the semantics
>> would be *after* any desugaring of multimethods.
> The goal is "DWIM", which is why we've circled around these implicit
> or low-cost-if-explicit approaches.
Of course DWIM is ill-defined, but bug 5856 and dups suggest much of
the problem comes from the language supporting numeric literals
written in base 10 with certain precision or significance, but then
mistreating them via conversion to binary and inevitable operation
using only binary operators.
> 1. changing the number type to decimal by fiat;
> 2. adding a "use decimal" pragma;
> 3. trying to keep literals generic.
> The high-cost explicit alternative is to tell 'em "use the m
> suffix!" That probably will not work out well in the real world.
> It's a syntax tax hike: it will require all user agents to be
> upgraded (unlike "use decimal"), and yet people will still forget to
> use the suffix.
> I'm still interested in better "use decimal" design ideas.
Allen made another proposal, which Waldemar mentioned in his notes
from the TC39 meeting:
4. All literals lex as decimal, string to number likewise converts to
decimal; but contagion is to binary, Math.sin/PI/etc. remain binary.
JSON would parse to decimal in this proposal.
This variation may require opt-in as Waldemar pointed out: people
write 1e400 to mean Infinity.
This variation preserves wrappers, so a Decimal converter function
(when invoked) and constructor (via new, and to hold a .prototype home
for methods). The committee plunks for more of this primitive/wrapper
business, since we have wrappers and primitives for numbers and other
types, and backward compatibility requires keeping them. Operators
work mostly as implemented already by Sam (results here, with some out-
of-date results; notably typeof 1.1m should be "decimal" not "object"
-- and not "number").
Sam and I are going to work on adapting Sam's SpiderMonkey
implementation, along with our existing ES3.1-based JSON codec and
trace-JITting code, to try this out. More details as we get into the
Since the bug is about usability, we have to prototype and test on
real users, ideally a significant number of users. We crave comments
and ideas from es-discuss too, of course.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Es-discuss