Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16550

Re: Specification error for Math.round

Date 2012-10-11 07:29 +0100
From Patricia Shanahan <pats@acm.org>
Newsgroups comp.lang.javascript
Subject Re: Specification error for Math.round
References <6dc8cb55-c29c-4bb2-ab6d-d9a9447cffd4@googlegroups.com>
Message-ID <sMudna--d5iv-uvNnZ2dnUVZ_tydnZ2d@earthlink.com> (permalink)

Show all headers | View raw


RobG wrote:
...
> The ES5 specification for Math.round(x)[1] says that:
> 
>   "If x is already an integer, the result is x"
> 
> and that:
> 
>   "The value of Math.round(x) is the same as the
>    value of Math.floor(x+0.5)"
...

The second rule introduces another oddity.

Most rounding is being done according to IEEE 754 round to nearest, in
which ties go to the even number. This particular rounding is sending
ties to the larger number. For example, Firefox gives "9" as the result
of "Math.round(8.5)".

That means that the inconsistency cannot be fixed by just saying that
the rounding is being done according to the normal round to nearest
rules, the way the corresponding function in java.lang.Math, rint(), is
specified. The second specification, or something equivalent to it, has
to be kept at least for non-integer inputs.

Patricia

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Specification error for Math.round RobG <rgqld@iinet.net.au> - 2012-10-10 19:52 -0700
  Re: Specification error for Math.round Patricia Shanahan <pats@acm.org> - 2012-10-11 07:29 +0100
    Re: Specification error for Math.round Dr J R Stockton <reply1241@merlyn.demon.co.uk.invalid> - 2012-10-12 23:00 +0100
  Re: Specification error for Math.round Danny <dann90038@gmail.com> - 2012-10-11 13:16 -0700
    Re: Specification error for Math.round Patricia Shanahan <pats@acm.org> - 2012-10-12 00:14 +0100
    Re: Specification error for Math.round RobG <rgqld@iinet.net.au> - 2012-10-11 21:46 -0700
      Re: Specification error for Math.round Patricia Shanahan <pats@acm.org> - 2012-10-12 08:28 +0100
        Re: Specification error for Math.round Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-13 22:14 +0200
          Re: Specification error for Math.round Patricia Shanahan <pats@acm.org> - 2012-10-13 21:45 +0100
            Re: Specification error for Math.round "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-13 23:59 +0200
        Re: Specification error for Math.round Dr J R Stockton <reply1241@merlyn.demon.co.uk.invalid> - 2012-10-13 19:31 +0100
      Re: Specification error for Math.round Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-14 11:09 +0000
  Re: Specification error for Math.round Dr J R Stockton <reply1241@merlyn.demon.co.uk.invalid> - 2012-10-12 22:48 +0100

csiph-web