| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = '9.6.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 |
var SECTION = "9.6"; |
| 38 |
var VERSION = "ECMA_1"; |
| 39 |
startTest(); |
| 40 |
|
| 41 |
writeHeaderToLog( SECTION + " Type Conversion: ToUint32"); |
| 42 |
|
| 43 |
new TestCase( SECTION, "0 >>> 0", 0, 0 >>> 0 ); |
| 44 |
|
| 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, "'+Infinity' >>> 0", 0, "+Infinity" >>> 0 ); |
| 49 |
new TestCase( SECTION, "Number.POSITIVE_INFINITY >>> 0", 0, Number.POSITIVE_INFINITY >>> 0 ); |
| 50 |
new TestCase( SECTION, "Number.NEGATIVE_INFINITY >>> 0", 0, Number.NEGATIVE_INFINITY >>> 0 ); |
| 51 |
new TestCase( SECTION, "Number.NaN >>> 0", 0, Number.NaN >>> 0 ); |
| 52 |
|
| 53 |
new TestCase( SECTION, "Number.MIN_VALUE >>> 0", 0, Number.MIN_VALUE >>> 0 ); |
| 54 |
new TestCase( SECTION, "-Number.MIN_VALUE >>> 0", 0, Number.MIN_VALUE >>> 0 ); |
| 55 |
new TestCase( SECTION, "0.1 >>> 0", 0, 0.1 >>> 0 ); |
| 56 |
new TestCase( SECTION, "-0.1 >>> 0", 0, -0.1 >>> 0 ); |
| 57 |
new TestCase( SECTION, "1 >>> 0", 1, 1 >>> 0 ); |
| 58 |
new TestCase( SECTION, "1.1 >>> 0", 1, 1.1 >>> 0 ); |
| 59 |
|
| 60 |
new TestCase( SECTION, "-1.1 >>> 0", ToUint32(-1.1), -1.1 >>> 0 ); |
| 61 |
new TestCase( SECTION, "-1 >>> 0", ToUint32(-1), -1 >>> 0 ); |
| 62 |
|
| 63 |
new TestCase( SECTION, "2147483647 >>> 0", ToUint32(2147483647), 2147483647 >>> 0 ); |
| 64 |
new TestCase( SECTION, "2147483648 >>> 0", ToUint32(2147483648), 2147483648 >>> 0 ); |
| 65 |
new TestCase( SECTION, "2147483649 >>> 0", ToUint32(2147483649), 2147483649 >>> 0 ); |
| 66 |
|
| 67 |
new TestCase( SECTION, "4294967295 >>> 0", ToUint32(4294967295), 4294967295 >>> 0 ); |
| 68 |
new TestCase( SECTION, "4294967296 >>> 0", ToUint32(4294967296), 4294967296 >>> 0 ); |
| 69 |
new TestCase( SECTION, "4294967297 >>> 0", ToUint32(4294967297), 4294967297 >>> 0 ); |
| 70 |
|
| 71 |
new TestCase( SECTION, "-2147483647 >>> 0", ToUint32(-2147483647), -2147483647 >>> 0 ); |
| 72 |
new TestCase( SECTION, "-2147483648 >>> 0", ToUint32(-2147483648), -2147483648 >>> 0 ); |
| 73 |
new TestCase( SECTION, "-2147483649 >>> 0", ToUint32(-2147483649), -2147483649 >>> 0 ); |
| 74 |
|
| 75 |
new TestCase( SECTION, "-4294967295 >>> 0", ToUint32(-4294967295), -4294967295 >>> 0 ); |
| 76 |
new TestCase( SECTION, "-4294967296 >>> 0", ToUint32(-4294967296), -4294967296 >>> 0 ); |
| 77 |
new TestCase( SECTION, "-4294967297 >>> 0", ToUint32(-4294967297), -4294967297 >>> 0 ); |
| 78 |
|
| 79 |
new TestCase( SECTION, "'2147483647' >>> 0", ToUint32(2147483647), '2147483647' >>> 0 ); |
| 80 |
new TestCase( SECTION, "'2147483648' >>> 0", ToUint32(2147483648), '2147483648' >>> 0 ); |
| 81 |
new TestCase( SECTION, "'2147483649' >>> 0", ToUint32(2147483649), '2147483649' >>> 0 ); |
| 82 |
|
| 83 |
new TestCase( SECTION, "'4294967295' >>> 0", ToUint32(4294967295), '4294967295' >>> 0 ); |
| 84 |
new TestCase( SECTION, "'4294967296' >>> 0", ToUint32(4294967296), '4294967296' >>> 0 ); |
| 85 |
new TestCase( SECTION, "'4294967297' >>> 0", ToUint32(4294967297), '4294967297' >>> 0 ); |
| 86 |
|
| 87 |
|
| 88 |
test(); |
| 89 |
|
| 90 |
function ToUint32( n ) { |
| 91 |
n = Number( n ); |
| 92 |
var sign = ( n < 0 ) ? -1 : 1; |
| 93 |
|
| 94 |
if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) { |
| 95 |
return 0; |
| 96 |
} |
| 97 |
n = sign * Math.floor( Math.abs(n) ) |
| 98 |
|
| 99 |
n = n % Math.pow(2,32); |
| 100 |
|
| 101 |
if ( n < 0 ){ |
| 102 |
n += Math.pow(2,32); |
| 103 |
} |
| 104 |
|
| 105 |
return ( n ); |
| 106 |
} |
| 107 |
|