{"action":"opened","issue":{"url":"https://api.github.com/repos/es-shims/es5-shim/issues/288","labels_url":"https://api.github.com/repos/es-shims/es5-shim/issues/288/labels{/name}","comments_url":"https://api.github.com/repos/es-shims/es5-shim/issues/288/comments","events_url":"https://api.github.com/repos/es-shims/es5-shim/issues/288/events","html_url":"https://github.com/es-shims/es5-shim/issues/288","id":54675477,"number":288,"title":"Math.round issues","user":{"login":"Yaffle","id":130792,"avatar_url":"https://avatars.githubusercontent.com/u/130792?v=3","gravatar_id":"","url":"https://api.github.com/users/Yaffle","html_url":"https://github.com/Yaffle","followers_url":"https://api.github.com/users/Yaffle/followers","following_url":"https://api.github.com/users/Yaffle/following{/other_user}","gists_url":"https://api.github.com/users/Yaffle/gists{/gist_id}","starred_url":"https://api.github.com/users/Yaffle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yaffle/subscriptions","organizations_url":"https://api.github.com/users/Yaffle/orgs","repos_url":"https://api.github.com/users/Yaffle/repos","events_url":"https://api.github.com/users/Yaffle/events{/privacy}","received_events_url":"https://api.github.com/users/Yaffle/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-17T21:14:13Z","updated_at":"2015-01-17T21:14:13Z","closed_at":null,"body":"see https://twitter.com/BrendanEich/status/360832908514181122\r\n\r\n1)\r\n`Math.round(0.5 - Number.EPSILON / 4)` should be equal to `0`\r\n\r\n2)\r\n`Math.round((Number.MAX_SAFE_INTEGER + 1) / 2 + 1)` should be equal to  `(Number.MAX_SAFE_INTEGER + 1) / 2 + 1`\r\n`Math.round(Number.MAX_SAFE_INTEGER)` should be equal to `Number.MAX_SAFE_INTEGER`\r\n\r\nThe ES5 spec - http://es5.github.io/#x15.8.2.15 - says, that `Math.round` \"Returns the Number value that is closest to x and is equal to a mathematical integer\", but `Note 2` says nothing about \r\n`Note 2` was fixed in ES6 - https://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.round\r\n\r\nSome browsers have good implementaions (FF 35, Chrome ?):\r\nhttps://bugzilla.mozilla.org/show_bug.cgi?id=622348\r\nhttps://bugzilla.mozilla.org/show_bug.cgi?id=1000606\r\n\r\nBut IE 11, Opera 12, Safari are buggy here.\r\n\r\nI think, the implementation may look like this:\r\n```\r\nMath.round = function (x) {\r\n  x = Number(x);\r\n  if (Math.abs(x) < 0.5) {\r\n    return x === 0 ? x : (x < 0 ? -0 : +0);\r\n  }\r\n  var y = Math.floor(x + 0.5);\r\n  return y - x === 1 ? x : y;\r\n};\r\n```\r\n"}}