Revisiting Decimal (generic algorithms)

Brendan Eich brendan at mozilla.com
Sun Jan 18 16:48:22 PST 2009


On Jan 16, 2009, at 7:38 PM, David-Sarah Hopwood wrote:

> It could be argued that most ES3.x programs are probably not relying
> on the exact errors introduced by double-precision IEEE 754, but that
> seems risky to me.

Emphatically agreed. People file dups of bug 5856 but they also  
knowingly and unknowingly depend on IEEE 754 behavior in detail.


> By that argument, ignoring performance, you could
> unconditionally implement all numbers as decimals, and I don't think
> many people here would accept that as being compatible.

This was the path favored by Mike Cowlishaw and (sometimes, IIRC) by  
Doug Crockford. It was rejected by at least me (for Mozilla) and  
Maciej (for Apple).


> To address the problem raised by Allen, you would probably want to
> implicitly define implementations that used different types for
> constants, depending on the argument types to a given function
> (and it is not clear how that would work for mixed-type arguments).

Another idea for constants that seems strictly more usable than any  
suffix requirement or complicated constant-parameter-based dispatch:  
"use decimal". The idea is to change the meaning of literals andn  
operators. Again the problem of built-ins, or really of interfacing  
with the rest of the world not scoped by the lexical pragma, remains.


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

* changing the number type to decimal by fiat;
* adding a "use decimal" pragma;
* 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.

/be


More information about the Es-discuss mailing list