A list of JavaScript quirks which should be kept in mind when writing implementations.
-
The JavaScript standard (ECMA-262) defines the behavior of
Math.roundsuch that "ties" (e.g.,1.5and-1.5) are rounded toward+infinity.var x = Math.round( 1.5 ); // returns 2.0 x = Math.round( -1.5 ); // returns -1.0
This behavior is relatively uncommon among languages implementing a round operation for floating-point numbers and appears to have originated by following Java.
When implementing lower-level math functions which may require rounding, exercise caution when considering whether the built-in rounding behavior is appropriate and ensure that bias is not introduced in computed results.