archives

« Bugzilla Issues Index

#2874 — 20.2.2.28 Math.round: Incorrect information in NOTE 2


20.2.2.28 Math.round ( x ), NOTE 2:

> NOTE 2 The value of Math.round(x) is the same as the value of
> Math.floor(x+0.5), except when x is -0 or is less than 0 but
> greater than or equal to -0.5; for these cases Math.round(x)
> returns -0, but Math.floor(x+0.5) returns +0.

The note suggests `Math.round(x)` can be implemented as `Math.floor(x + 0.5)` if x > 0 (and x being an ECMAScript number value - not a mathematical real number as defined in "5.2 Algorithm Conventions"). This violates bullet point 6:

> If x is greater than 0 but less than 0.5, the result is +0.

Various implementations follow the note rather than the exact specification (IE11, Nashorn, JSC, SpiderMonkey), so the note should probably be altered to say that `Math.round(x)` is not the same as `Math.floor(x + 0.5)` if x ∈ [-0.5, 0.5).

Related: https://bugzilla.mozilla.org/show_bug.cgi?id=1000606


test case:
---
0 === Math.round(0.499999999999999944488848768742172978818416595458984375)
---


fixed in rev25 editor's draft


fixed in rev25 editor's draft