roundTiesToEven
Graydon Hoare
graydon at mozilla.com
Mon Nov 12 18:24:03 PST 2007
Jonathan Watt wrote:
> liorean wrote:
>> On 11/11/2007, Jonathan Watt <jwatt at jwatt.org> wrote:
>>> I've noticed that rounding in the reference implementation is implemented using
>>> IEEE roundTiesToEven, but in browsers .5 values appear to round towards zero.
>>> Although roundTiesToEven is desirable from a computational point of view,
>>> there's likely a significant risk that changing to this method could break some
>>> existing ECMAScript.
>> That's really serious breakage
>
> Well, it's likely only a small bug in the reference implementation rather than a
> requirement of the specification, so not too big a deal I'd think.
>
>> - books, tutorials, references and real
>> world code all take for granted that halves alway round up.
>
> Err, right. Round up, not round to zero. Thanks for the correction.
I believe there is some confusion here. There is no proposed change to
the *binary* floating point operations in ES4, relative to ES3.
There is a new datatype for *decimal* floating point, and this datatype
has a different default rounding mode than the rounding mode in ES3
binary floating point. But this datatype has a wide variety of
arithmetical differences. In particular:
- You can actually represent 0.5 in the first place! Binary floating
point cannot. Decimal can. In the default decimal context, 0.5 + 0.5
gives an exact decimal answer; there is no rounding to worry about.
- You can adjust the rounding modes and precision used for decimal
arithmetic, to precisely match your local monetary / banking / tax
regulations. The choice of half-even as a default mode is based on
precedent of other decimal libraries and banking locales. See the
sage advice of Mike Cowlishaw on choice of decimal rounding modes:
http://www2.hursley.ibm.com/decimal/decifaq1.html#rounding
There is no existing ES3 code in the wild that uses decimal arithmetic
at all, much less a particular decimal rounding mode.
-Graydon
More information about the Es4-discuss
mailing list