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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // ES5 15.1.2.2 step 1
michael@0 2
michael@0 3 /*
michael@0 4 * Boundary testing for super-large positive numbers between non-exponential
michael@0 5 * and in-exponential-form.
michael@0 6 *
michael@0 7 * NB: While 1e21 is exactly representable as an IEEE754 double-precision
michael@0 8 * number, its nearest neighboring representable values are a good distance
michael@0 9 * away, 65536 to be precise.
michael@0 10 */
michael@0 11
michael@0 12 // This is the boundary in theory.
michael@0 13 assertEq(parseInt(1e21), 1);
michael@0 14
michael@0 15 // This is the boundary in practice.
michael@0 16 assertEq(parseInt(1e21 - 65537) > 1e20, true);
michael@0 17 assertEq(parseInt(1e21 - 65536), 1);
michael@0 18 assertEq(parseInt(1e21 + 65536), 1);
michael@0 19
michael@0 20 // Check that we understand floating point accuracy near the boundary
michael@0 21 assertEq(1e21 - 65537 !== 1e21 - 65536, true);
michael@0 22 assertEq(1e21 - 65536, 1e21);
michael@0 23 assertEq(1e21 + 65535, 1e21);
michael@0 24 assertEq(1e21 + 65536, 1e21);
michael@0 25
michael@0 26 // ES5 leaves exact precision in ToString(bigMagNum) undefined, which
michael@0 27 // might make this value inconsistent across implementations (maybe,
michael@0 28 // nobody's done the math here). Regardless, it's definitely a number
michael@0 29 // very close to 1, and not a large-magnitude positive number.
michael@0 30 assertEq(1e21 + 65537 !== 1e21, true);
michael@0 31 assertEq(parseInt(1e21 + 65537) < 1.001, true);
michael@0 32
michael@0 33
michael@0 34 /*
michael@0 35 * Now do the same tests for super-large negative numbers crossing the
michael@0 36 * opposite boundary.
michael@0 37 */
michael@0 38
michael@0 39 // This is the boundary in theory.
michael@0 40 assertEq(parseInt(-1e21), -1);
michael@0 41
michael@0 42 // This is the boundary in practice.
michael@0 43 assertEq(parseInt(-1e21 + 65537) < -1e20, true);
michael@0 44 assertEq(parseInt(-1e21 + 65536), -1);
michael@0 45 assertEq(parseInt(-1e21 - 65536), -1);
michael@0 46
michael@0 47 // Check that we understand floating point accuracy near the boundary
michael@0 48 assertEq(-1e21 + 65537 !== -1e21 + 65536, true);
michael@0 49 assertEq(-1e21 + 65536, -1e21);
michael@0 50 assertEq(-1e21 - 65535, -1e21);
michael@0 51 assertEq(-1e21 - 65536, -1e21);
michael@0 52
michael@0 53 // ES5 leaves exact precision in ToString(bigMagNum) undefined, which
michael@0 54 // might make this value inconsistent across implementations (maybe,
michael@0 55 // nobody's done the math here). Regardless, it's definitely a number
michael@0 56 // very close to -1, and not a large-magnitude negative number.
michael@0 57 assertEq(-1e21 - 65537 !== 1e21, true);
michael@0 58 assertEq(parseInt(-1e21 - 65537) > -1.001, true);
michael@0 59
michael@0 60
michael@0 61 /* Check values around the boundary. */
michael@0 62 arr = [1e0, 5e1, 9e19, 0.1e20, 1.3e20, 1e20, 9e20, 9.99e20, 0.1e21,
michael@0 63 1e21, 1.0e21, 2e21, 2e20, 2.1e22, 9e21, 0.1e22, 1e22, 3e46, 3e23, 3e100, 3.4e200, 7e1000,
michael@0 64 1e21, 1e21+65537, 1e21+65536, 1e21-65536, 1e21-65537];
michael@0 65
michael@0 66 /* Check across a range of values in case we missed anything. */
michael@0 67 for (var i = 0; i < 4000; i++) {
michael@0 68 arr.push(1e19 + i*1e19);
michael@0 69 }
michael@0 70
michael@0 71 for (var i in arr) {
michael@0 72 assertEq(parseInt( arr[i]), parseInt(String( arr[i])));
michael@0 73 assertEq(parseInt(-arr[i]), parseInt(String(-arr[i])));
michael@0 74 }
michael@0 75
michael@0 76

mercurial