js/src/jit-test/tests/basic/bug653153.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/basic/bug653153.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +// ES5 15.1.2.2 step 1
     1.5 +
     1.6 +/*
     1.7 + * Boundary testing for super-large positive numbers between non-exponential
     1.8 + * and in-exponential-form.
     1.9 + *
    1.10 + * NB: While 1e21 is exactly representable as an IEEE754 double-precision
    1.11 + * number, its nearest neighboring representable values are a good distance
    1.12 + * away, 65536 to be precise.
    1.13 + */
    1.14 +
    1.15 +// This is the boundary in theory.
    1.16 +assertEq(parseInt(1e21), 1);
    1.17 +
    1.18 +// This is the boundary in practice.
    1.19 +assertEq(parseInt(1e21 - 65537) > 1e20, true);
    1.20 +assertEq(parseInt(1e21 - 65536), 1);
    1.21 +assertEq(parseInt(1e21 + 65536), 1);
    1.22 +
    1.23 +// Check that we understand floating point accuracy near the boundary
    1.24 +assertEq(1e21 - 65537 !== 1e21 - 65536, true);
    1.25 +assertEq(1e21 - 65536, 1e21);
    1.26 +assertEq(1e21 + 65535, 1e21);
    1.27 +assertEq(1e21 + 65536, 1e21);
    1.28 +
    1.29 +// ES5 leaves exact precision in ToString(bigMagNum) undefined, which
    1.30 +// might make this value inconsistent across implementations (maybe,
    1.31 +// nobody's done the math here).  Regardless, it's definitely a number
    1.32 +// very close to 1, and not a large-magnitude positive number.
    1.33 +assertEq(1e21 + 65537 !== 1e21, true);
    1.34 +assertEq(parseInt(1e21 + 65537) < 1.001, true);
    1.35 +
    1.36 +
    1.37 +/*
    1.38 + * Now do the same tests for super-large negative numbers crossing the
    1.39 + * opposite boundary.
    1.40 + */
    1.41 +
    1.42 +// This is the boundary in theory.
    1.43 +assertEq(parseInt(-1e21), -1);
    1.44 +
    1.45 +// This is the boundary in practice.
    1.46 +assertEq(parseInt(-1e21 + 65537) < -1e20, true);
    1.47 +assertEq(parseInt(-1e21 + 65536), -1);
    1.48 +assertEq(parseInt(-1e21 - 65536), -1);
    1.49 +
    1.50 +// Check that we understand floating point accuracy near the boundary
    1.51 +assertEq(-1e21 + 65537 !== -1e21 + 65536, true);
    1.52 +assertEq(-1e21 + 65536, -1e21);
    1.53 +assertEq(-1e21 - 65535, -1e21);
    1.54 +assertEq(-1e21 - 65536, -1e21);
    1.55 +
    1.56 +// ES5 leaves exact precision in ToString(bigMagNum) undefined, which
    1.57 +// might make this value inconsistent across implementations (maybe,
    1.58 +// nobody's done the math here).  Regardless, it's definitely a number
    1.59 +// very close to -1, and not a large-magnitude negative number.
    1.60 +assertEq(-1e21 - 65537 !== 1e21, true);
    1.61 +assertEq(parseInt(-1e21 - 65537) > -1.001, true);
    1.62 +
    1.63 +
    1.64 +/* Check values around the boundary. */
    1.65 +arr = [1e0, 5e1, 9e19, 0.1e20, 1.3e20, 1e20, 9e20, 9.99e20, 0.1e21,
    1.66 +       1e21, 1.0e21, 2e21, 2e20, 2.1e22, 9e21, 0.1e22, 1e22, 3e46, 3e23, 3e100, 3.4e200, 7e1000,
    1.67 +       1e21, 1e21+65537, 1e21+65536, 1e21-65536, 1e21-65537]; 
    1.68 +
    1.69 +/* Check across a range of values in case we missed anything. */
    1.70 +for (var i = 0; i < 4000; i++) {
    1.71 +    arr.push(1e19 + i*1e19);
    1.72 +}
    1.73 +
    1.74 +for (var i in arr) {
    1.75 +    assertEq(parseInt( arr[i]), parseInt(String( arr[i])));
    1.76 +    assertEq(parseInt(-arr[i]), parseInt(String(-arr[i])));
    1.77 +}
    1.78 +
    1.79 +

mercurial