ES3.1 Proposal Working Draft

Brendan Eich brendan at mozilla.org
Thu Feb 21 01:36:52 PST 2008


On Feb 20, 2008, at 1:25 PM, Mark S. Miller wrote:

> What numbers are representable as double but not decimal?

Mike Cowlishaw's page at http://www2.hursley.ibm.com/decimal/ is  
extremely informative, especially http://www2.hursley.ibm.com/decimal/ 
decifaq.html; see also the link to http://grouper.ieee.org/groups/754/.

See http://www2.hursley.ibm.com/decimal/decifaq6.html#bindigits and  
http://www2.hursley.ibm.com/decimal/decifaq6.html#binapprox for  
double to decimal conversion answers. As http://wiki.ecmascript.org/ 
doku.php?id=proposals:decimal summarizes:

* A very small amount of precision which may be present in a double- 
precision binary fp number is lost during a double → decimal  
promotion, but that:
     o No precision is lost in an integral → decimal promotion.
     o Reading a numeric lexeme as a decimal preserves more precision  
than reading it as a double.

> Does decimal have NaN, Infinity, -Infinity,

Yes -- from the ES4 RI:

   >> -1.0m/0.0m
   -Infinity
   >> 1.0m/0.0m
   Infinity
   >> 0.0m/0.0m
   NaN

> and -0.0?

Yes:

 >> 1.0m/-0.0m
-Infinity

> (Btw, I never liked -0.0. And I especially dislike ES3's
> behavior that 0.0 === -0.0. However, I would argue against making
> incompatible changes to this.)

Guy Steele edited Edition 1 of ECMA-262 and argued for both of these  
parts of the standard, based on precedent in related programming  
languages, as well as advice in IEEE-754 itself. He pointed out  
something important to numerical programmers: you can walk around the  
four quadrants using signed zeros with atan2:

js> Math.atan2(0,0)
0
js> Math.atan2(-0,0)
0
js> Math.atan2(-0,-0)
-3.141592653589793
js> Math.atan2(0,-0)
3.141592653589793

/be




More information about the Es4-discuss mailing list