michael@0: // ES5 15.1.2.2 step 1 michael@0: michael@0: /* michael@0: * Boundary testing for super-large positive numbers between non-exponential michael@0: * and in-exponential-form. michael@0: * michael@0: * NB: While 1e21 is exactly representable as an IEEE754 double-precision michael@0: * number, its nearest neighboring representable values are a good distance michael@0: * away, 65536 to be precise. michael@0: */ michael@0: michael@0: // This is the boundary in theory. michael@0: assertEq(parseInt(1e21), 1); michael@0: michael@0: // This is the boundary in practice. michael@0: assertEq(parseInt(1e21 - 65537) > 1e20, true); michael@0: assertEq(parseInt(1e21 - 65536), 1); michael@0: assertEq(parseInt(1e21 + 65536), 1); michael@0: michael@0: // Check that we understand floating point accuracy near the boundary michael@0: assertEq(1e21 - 65537 !== 1e21 - 65536, true); michael@0: assertEq(1e21 - 65536, 1e21); michael@0: assertEq(1e21 + 65535, 1e21); michael@0: assertEq(1e21 + 65536, 1e21); michael@0: michael@0: // ES5 leaves exact precision in ToString(bigMagNum) undefined, which michael@0: // might make this value inconsistent across implementations (maybe, michael@0: // nobody's done the math here). Regardless, it's definitely a number michael@0: // very close to 1, and not a large-magnitude positive number. michael@0: assertEq(1e21 + 65537 !== 1e21, true); michael@0: assertEq(parseInt(1e21 + 65537) < 1.001, true); michael@0: michael@0: michael@0: /* michael@0: * Now do the same tests for super-large negative numbers crossing the michael@0: * opposite boundary. michael@0: */ michael@0: michael@0: // This is the boundary in theory. michael@0: assertEq(parseInt(-1e21), -1); michael@0: michael@0: // This is the boundary in practice. michael@0: assertEq(parseInt(-1e21 + 65537) < -1e20, true); michael@0: assertEq(parseInt(-1e21 + 65536), -1); michael@0: assertEq(parseInt(-1e21 - 65536), -1); michael@0: michael@0: // Check that we understand floating point accuracy near the boundary michael@0: assertEq(-1e21 + 65537 !== -1e21 + 65536, true); michael@0: assertEq(-1e21 + 65536, -1e21); michael@0: assertEq(-1e21 - 65535, -1e21); michael@0: assertEq(-1e21 - 65536, -1e21); michael@0: michael@0: // ES5 leaves exact precision in ToString(bigMagNum) undefined, which michael@0: // might make this value inconsistent across implementations (maybe, michael@0: // nobody's done the math here). Regardless, it's definitely a number michael@0: // very close to -1, and not a large-magnitude negative number. michael@0: assertEq(-1e21 - 65537 !== 1e21, true); michael@0: assertEq(parseInt(-1e21 - 65537) > -1.001, true); michael@0: michael@0: michael@0: /* Check values around the boundary. */ michael@0: arr = [1e0, 5e1, 9e19, 0.1e20, 1.3e20, 1e20, 9e20, 9.99e20, 0.1e21, michael@0: 1e21, 1.0e21, 2e21, 2e20, 2.1e22, 9e21, 0.1e22, 1e22, 3e46, 3e23, 3e100, 3.4e200, 7e1000, michael@0: 1e21, 1e21+65537, 1e21+65536, 1e21-65536, 1e21-65537]; michael@0: michael@0: /* Check across a range of values in case we missed anything. */ michael@0: for (var i = 0; i < 4000; i++) { michael@0: arr.push(1e19 + i*1e19); michael@0: } michael@0: michael@0: for (var i in arr) { michael@0: assertEq(parseInt( arr[i]), parseInt(String( arr[i]))); michael@0: assertEq(parseInt(-arr[i]), parseInt(String(-arr[i]))); michael@0: } michael@0: michael@0: