As Mark Dickinson noted in a comment on this subject, the ECMA-262 ECMAScript Language Specification requires the use of the IEEE 754 64-bit binary floating-point to represent the type of number . Relevant rounding rules: "Select the member of this set that is closest to the value of x. If the two values ββof the set are equally close, select the one that has an even value ...".
These rules are general, applying arithmetic results as well as literal values ββto rounding.
Listed below are all the numbers in the corresponding range for the question, which are exactly represented in the IEEE 754 64-bit binary floating point. Each of them is shown as its decimal value, as well as a hexadecimal representation of its bit diagram. A number with an even value has the smallest hexadecimal digit in the bitmap.
9007199254740992 bit pattern 0x4340000000000000 9007199254740994 bit pattern 0x4340000000000001 9007199254740996 bit pattern 0x4340000000000002 9007199254740998 bit pattern 0x4340000000000003 9007199254741000 bit pattern 0x4340000000000004
Each of the even inputs is one of these numbers and rounds to this number. Each of the odd inputs is exactly halfway between the two of them, and the rounds are with an even value. This results in rounding of the odd entries to 9007199254740992, 9007199254740996 and 9007199254741000.
Patricia Shanahan Jun 25 '14 at 3:25 2014-06-25 03:25
source share