Revisiting Decimal (generic algorithms)

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Fri Jan 16 17:20:51 PST 2009


Allen Wirfs-Brock wrote:
[...]
> function fuzz(a) { return a + 0.1}
> //not generic in Kona draft, fuzz(1m) ===> 1.10000000000000008881784197001... (but see below)
> //Kona spec. uses binary floating point for all mixed mode operations
> 
[...]
> This problem cannot be fixed simply by tweaking the coercion rules.
> It probably requires that numeric literals be treated as generic values
> that are only interpreted situationally as either binary or decimal values
> in the context of a particular operations.

I am not aware of any precedent for this approach in other languages, and
I'm very skeptical about whether it can be made to work in ECMAScript.
Consider

  function id(x) { return x; }

What is the result and type of id(0.1) in this approach, and why?

-- 
David-Sarah Hopwood


More information about the Es-discuss mailing list