1 // Copyright 2014 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Flags: --allow-natives-syntax 6 7 function g1(i) { 8 var x = i * 1; 9 return (x >>> 0) % 1000000000000; 10 } 11 12 function g2(i) { 13 var x = i * 1; 14 return ((x >>> 0) % 1000000000000) | 0; 15 } 16 17 function test1() { 18 assertEquals(2294967296, g1(-2000000000)); 19 assertEquals(2294967295, g1(-2000000001)); 20 assertEquals(2294967290, g1(-2000000006)); 21 22 assertEquals(2147483651, g1(-2147483645)); 23 assertEquals(2147483650, g1(-2147483646)); 24 assertEquals(2147483649, g1(-2147483647)); 25 assertEquals(2147483648, g1(-2147483648)); 26 assertEquals(2147483647, g1(-2147483649)); 27 28 assertEquals(3000000000, g1(3000000000)); 29 assertEquals(3000000001, g1(3000000001)); 30 assertEquals(3000000002, g1(3000000002)); 31 32 assertEquals(4000000000, g1(4000000000)); 33 assertEquals(4000400001, g1(4000400001)); 34 assertEquals(4000400002, g1(4000400002)); 35 36 assertEquals(3, g1(4294967299)); 37 assertEquals(2, g1(4294967298)); 38 assertEquals(1, g1(4294967297)); 39 assertEquals(0, g1(4294967296)); 40 assertEquals(4294967295, g1(4294967295)); 41 assertEquals(4294967294, g1(4294967294)); 42 assertEquals(4294967293, g1(4294967293)); 43 assertEquals(4294967292, g1(4294967292)); 44 } 45 46 %NeverOptimizeFunction(test1); 47 test1(); 48 49 function test2() { 50 assertEquals(-2000000000, g2(-2000000000)); 51 assertEquals(-2000000001, g2(-2000000001)); 52 assertEquals(-2000000006, g2(-2000000006)); 53 54 assertEquals(-2147483645, g2(-2147483645)); 55 assertEquals(-2147483646, g2(-2147483646)); 56 assertEquals(-2147483647, g2(-2147483647)); 57 assertEquals(-2147483648, g2(-2147483648)); 58 assertEquals(2147483647, g2(-2147483649)); 59 60 assertEquals(-1294967296, g2(3000000000)); 61 assertEquals(-1294967295, g2(3000000001)); 62 assertEquals(-1294967294, g2(3000000002)); 63 64 assertEquals(-294967296, g2(4000000000)); 65 assertEquals(-294567295, g2(4000400001)); 66 assertEquals(-294567294, g2(4000400002)); 67 68 assertEquals(3, g2(4294967299)); 69 assertEquals(2, g2(4294967298)); 70 assertEquals(1, g2(4294967297)); 71 assertEquals(0, g2(4294967296)); 72 assertEquals(-1, g2(4294967295)); 73 assertEquals(-2, g2(4294967294)); 74 assertEquals(-3, g2(4294967293)); 75 assertEquals(-4, g2(4294967292)); 76 } 77 78 %NeverOptimizeFunction(test2); 79 test2(); 80