| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = '9.5-2.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
var SECTION = "9.5-2"; |
| 39 |
var VERSION = "ECMA_1"; |
| 40 |
startTest(); |
| 41 |
|
| 42 |
writeHeaderToLog( SECTION + " ToInt32"); |
| 43 |
|
| 44 |
new TestCase( SECTION, "0 << 0", 0, 0 << 0 ); |
| 45 |
new TestCase( SECTION, "-0 << 0", 0, -0 << 0 ); |
| 46 |
new TestCase( SECTION, "Infinity << 0", 0, "Infinity" << 0 ); |
| 47 |
new TestCase( SECTION, "-Infinity << 0", 0, "-Infinity" << 0 ); |
| 48 |
new TestCase( SECTION, "Number.POSITIVE_INFINITY << 0", 0, Number.POSITIVE_INFINITY << 0 ); |
| 49 |
new TestCase( SECTION, "Number.NEGATIVE_INFINITY << 0", 0, Number.NEGATIVE_INFINITY << 0 ); |
| 50 |
new TestCase( SECTION, "Number.NaN << 0", 0, Number.NaN << 0 ); |
| 51 |
|
| 52 |
new TestCase( SECTION, "Number.MIN_VALUE << 0", 0, Number.MIN_VALUE << 0 ); |
| 53 |
new TestCase( SECTION, "-Number.MIN_VALUE << 0", 0, -Number.MIN_VALUE << 0 ); |
| 54 |
new TestCase( SECTION, "0.1 << 0", 0, 0.1 << 0 ); |
| 55 |
new TestCase( SECTION, "-0.1 << 0", 0, -0.1 << 0 ); |
| 56 |
new TestCase( SECTION, "1 << 0", 1, 1 << 0 ); |
| 57 |
new TestCase( SECTION, "1.1 << 0", 1, 1.1 << 0 ); |
| 58 |
new TestCase( SECTION, "-1 << 0", ToInt32(-1), -1 << 0 ); |
| 59 |
|
| 60 |
|
| 61 |
new TestCase( SECTION, "2147483647 << 0", ToInt32(2147483647), 2147483647 << 0 ); |
| 62 |
new TestCase( SECTION, "2147483648 << 0", ToInt32(2147483648), 2147483648 << 0 ); |
| 63 |
new TestCase( SECTION, "2147483649 << 0", ToInt32(2147483649), 2147483649 << 0 ); |
| 64 |
|
| 65 |
new TestCase( SECTION, "(Math.pow(2,31)-1) << 0", ToInt32(2147483647), (Math.pow(2,31)-1) << 0 ); |
| 66 |
new TestCase( SECTION, "Math.pow(2,31) << 0", ToInt32(2147483648), Math.pow(2,31) << 0 ); |
| 67 |
new TestCase( SECTION, "(Math.pow(2,31)+1) << 0", ToInt32(2147483649), (Math.pow(2,31)+1) << 0 ); |
| 68 |
|
| 69 |
new TestCase( SECTION, "(Math.pow(2,32)-1) << 0", ToInt32(4294967295), (Math.pow(2,32)-1) << 0 ); |
| 70 |
new TestCase( SECTION, "(Math.pow(2,32)) << 0", ToInt32(4294967296), (Math.pow(2,32)) << 0 ); |
| 71 |
new TestCase( SECTION, "(Math.pow(2,32)+1) << 0", ToInt32(4294967297), (Math.pow(2,32)+1) << 0 ); |
| 72 |
|
| 73 |
new TestCase( SECTION, "4294967295 << 0", ToInt32(4294967295), 4294967295 << 0 ); |
| 74 |
new TestCase( SECTION, "4294967296 << 0", ToInt32(4294967296), 4294967296 << 0 ); |
| 75 |
new TestCase( SECTION, "4294967297 << 0", ToInt32(4294967297), 4294967297 << 0 ); |
| 76 |
|
| 77 |
new TestCase( SECTION, "'2147483647' << 0", ToInt32(2147483647), '2147483647' << 0 ); |
| 78 |
new TestCase( SECTION, "'2147483648' << 0", ToInt32(2147483648), '2147483648' << 0 ); |
| 79 |
new TestCase( SECTION, "'2147483649' << 0", ToInt32(2147483649), '2147483649' << 0 ); |
| 80 |
|
| 81 |
new TestCase( SECTION, "'4294967295' << 0", ToInt32(4294967295), '4294967295' << 0 ); |
| 82 |
new TestCase( SECTION, "'4294967296' << 0", ToInt32(4294967296), '4294967296' << 0 ); |
| 83 |
new TestCase( SECTION, "'4294967297' << 0", ToInt32(4294967297), '4294967297' << 0 ); |
| 84 |
|
| 85 |
new TestCase( SECTION, "-2147483647 << 0", ToInt32(-2147483647), -2147483647 << 0 ); |
| 86 |
new TestCase( SECTION, "-2147483648 << 0", ToInt32(-2147483648), -2147483648 << 0 ); |
| 87 |
new TestCase( SECTION, "-2147483649 << 0", ToInt32(-2147483649), -2147483649 << 0 ); |
| 88 |
|
| 89 |
new TestCase( SECTION, "-4294967295 << 0", ToInt32(-4294967295), -4294967295 << 0 ); |
| 90 |
new TestCase( SECTION, "-4294967296 << 0", ToInt32(-4294967296), -4294967296 << 0 ); |
| 91 |
new TestCase( SECTION, "-4294967297 << 0", ToInt32(-4294967297), -4294967297 << 0 ); |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
new TestCase( SECTION, "2147483648.25 << 0", ToInt32(2147483648.25), 2147483648.25 << 0 ); |
| 98 |
new TestCase( SECTION, "2147483648.5 << 0", ToInt32(2147483648.5), 2147483648.5 << 0 ); |
| 99 |
new TestCase( SECTION, "2147483648.75 << 0", ToInt32(2147483648.75), 2147483648.75 << 0 ); |
| 100 |
new TestCase( SECTION, "4294967295.25 << 0", ToInt32(4294967295.25), 4294967295.25 << 0 ); |
| 101 |
new TestCase( SECTION, "4294967295.5 << 0", ToInt32(4294967295.5), 4294967295.5 << 0 ); |
| 102 |
new TestCase( SECTION, "4294967295.75 << 0", ToInt32(4294967295.75), 4294967295.75 << 0 ); |
| 103 |
new TestCase( SECTION, "3000000000.25 << 0", ToInt32(3000000000.25), 3000000000.25 << 0 ); |
| 104 |
new TestCase( SECTION, "3000000000.5 << 0", ToInt32(3000000000.5), 3000000000.5 << 0 ); |
| 105 |
new TestCase( SECTION, "3000000000.75 << 0", ToInt32(3000000000.75), 3000000000.75 << 0 ); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
new TestCase( SECTION, "-2147483648.25 << 0", ToInt32(-2147483648.25), -2147483648.25 << 0 ); |
| 111 |
new TestCase( SECTION, "-2147483648.5 << 0", ToInt32(-2147483648.5), -2147483648.5 << 0 ); |
| 112 |
new TestCase( SECTION, "-2147483648.75 << 0", ToInt32(-2147483648.75), -2147483648.75 << 0 ); |
| 113 |
new TestCase( SECTION, "-4294967295.25 << 0", ToInt32(-4294967295.25), -4294967295.25 << 0 ); |
| 114 |
new TestCase( SECTION, "-4294967295.5 << 0", ToInt32(-4294967295.5), -4294967295.5 << 0 ); |
| 115 |
new TestCase( SECTION, "-4294967295.75 << 0", ToInt32(-4294967295.75), -4294967295.75 << 0 ); |
| 116 |
new TestCase( SECTION, "-3000000000.25 << 0", ToInt32(-3000000000.25), -3000000000.25 << 0 ); |
| 117 |
new TestCase( SECTION, "-3000000000.5 << 0", ToInt32(-3000000000.5), -3000000000.5 << 0 ); |
| 118 |
new TestCase( SECTION, "-3000000000.75 << 0", ToInt32(-3000000000.75), -3000000000.75 << 0 ); |
| 119 |
|
| 120 |
|
| 121 |
test(); |
| 122 |
|
| 123 |
function ToInt32( n ) { |
| 124 |
n = Number( n ); |
| 125 |
var sign = ( n < 0 ) ? -1 : 1; |
| 126 |
|
| 127 |
if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) { |
| 128 |
return 0; |
| 129 |
} |
| 130 |
|
| 131 |
n = (sign * Math.floor( Math.abs(n) )) % Math.pow(2,32); |
| 132 |
if ( sign == -1 ) { |
| 133 |
n = ( n < -Math.pow(2,31) ) ? n + Math.pow(2,32) : n; |
| 134 |
} else{ |
| 135 |
n = ( n >= Math.pow(2,31) ) ? n - Math.pow(2,32) : n; |
| 136 |
} |
| 137 |
|
| 138 |
return ( n ); |
| 139 |
} |
| 140 |
|