Skip to content

Latest commit

 

History

History
49 lines (30 loc) · 1.67 KB

javascript_quirks.md

File metadata and controls

49 lines (30 loc) · 1.67 KB

JavaScript Quirks

A list of JavaScript quirks which should be kept in mind when writing implementations.

Rounding

  1. The JavaScript standard (ECMA-262) defines the behavior of Math.round such that "ties" (e.g., 1.5 and -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.