]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Expressions/11.7.3.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
24 ECMA Section: 11.7.3 The unsigned right shift operator ( >>> )
26 11.7.3 The unsigned right shift operator ( >>> )
27 Performs a zero-filling bitwise right shift operation on the left argument
28 by the amount specified by the right argument.
30 The production ShiftExpression : ShiftExpression >>> AdditiveExpression is
33 1. Evaluate ShiftExpression.
34 2. Call GetValue(Result(1)).
35 3. Evaluate AdditiveExpression.
36 4. Call GetValue(Result(3)).
37 5. Call ToUint32(Result(2)).
38 6. Call ToUint32(Result(4)).
39 7. Mask out all but the least significant 5 bits of Result(6), that is,
40 compute Result(6) & 0x1F.
41 8. Perform zero-filling right shift of Result(5) by Result(7) bits.
42 Vacated bits are filled with zero. The result is an unsigned 32 bit
46 Author: christine@netscape.com
47 Date: 12 november 1997
49 var SECTION
= "11.7.3";
50 var VERSION
= "ECMA_1";
52 var testcases
= getTestCases();
54 writeHeaderToLog( SECTION
+ " The unsigned right shift operator ( >>> )");
58 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
59 testcases
[tc
].passed
= writeTestCaseResult(
62 testcases
[tc
].description
+" = "+
63 testcases
[tc
].actual
);
65 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
70 function getTestCases() {
71 var array
= new Array();
77 for ( power
= 0; power
<= 32; power
++ ) {
78 shiftexp
= Math
.pow( 2, power
);
80 for ( addexp
= 0; addexp
<= 32; addexp
++ ) {
81 array
[item
++] = new TestCase( SECTION
,
82 shiftexp
+ " >>> " + addexp
,
83 UnsignedRightShift( shiftexp
, addexp
),
84 shiftexp
>>> addexp
);
91 function ToInteger( n
) {
93 var sign
= ( n
< 0 ) ? -1 : 1;
98 if ( Math
.abs( n
) == 0 || Math
.abs( n
) == Number
.POSITIVE_INFINITY
) {
101 return ( sign
* Math
.floor(Math
.abs(n
)) );
103 function ToInt32( n
) {
105 var sign
= ( n
< 0 ) ? -1 : 1;
107 if ( Math
.abs( n
) == 0 || Math
.abs( n
) == Number
.POSITIVE_INFINITY
) {
111 n
= (sign
* Math
.floor( Math
.abs(n
) )) % Math
.pow(2,32);
112 n
= ( n
>= Math
.pow(2,31) ) ? n
- Math
.pow(2,32) : n
;
116 function ToUint32( n
) {
118 var sign
= ( n
< 0 ) ? -1 : 1;
120 if ( Math
.abs( n
) == 0 || Math
.abs( n
) == Number
.POSITIVE_INFINITY
) {
123 n
= sign
* Math
.floor( Math
.abs(n
) )
125 n
= n
% Math
.pow(2,32);
133 function ToUint16( n
) {
134 var sign
= ( n
< 0 ) ? -1 : 1;
136 if ( Math
.abs( n
) == 0 || Math
.abs( n
) == Number
.POSITIVE_INFINITY
) {
140 n
= ( sign
* Math
.floor( Math
.abs(n
) ) ) % Math
.pow(2,16);
148 function Mask( b
, n
) {
149 b
= ToUint32BitString( b
);
150 b
= b
.substring( b
.length
- n
);
151 b
= ToUint32Decimal( b
);
154 function ToUint32BitString( n
) {
156 for ( p
= 31; p
>=0; p
-- ) {
157 if ( n
>= Math
.pow(2,p
) ) {
166 function ToInt32BitString( n
) {
168 var sign
= ( n
< 0 ) ? -1 : 1;
170 b
+= ( sign
== 1 ) ? "0" : "1";
172 for ( p
= 30; p
>=0; p
-- ) {
173 if ( (sign
== 1 ) ? sign
* n
>= Math
.pow(2,p
) : sign
* n
> Math
.pow(2,p
) ) {
174 b
+= ( sign
== 1 ) ? "1" : "0";
175 n
-= sign
* Math
.pow( 2, p
);
177 b
+= ( sign
== 1 ) ? "0" : "1";
183 function ToInt32Decimal( bin
) {
187 if ( Number(bin
.charAt(0)) == 0 ) {
192 r
= -(Math
.pow(2,31));
195 for ( var j
= 0; j
< 31; j
++ ) {
196 r
+= Math
.pow( 2, j
) * Number(bin
.charAt(31-j
));
201 function ToUint32Decimal( bin
) {
205 for ( l
= bin
.length
; l
< 32; l
++ ) {
209 for ( j
= 0; j
< 32; j
++ ) {
210 r
+= Math
.pow( 2, j
) * Number(bin
.charAt(31-j
));
216 function RShift( s
, a
) {
217 s
= ToUint32BitString( s
);
218 for ( z
= 0; z
< a
; z
++ ) {
221 s
= s
.substring( 0, s
.length
- a
);
223 return ToUint32Decimal(s
);
225 function UnsignedRightShift( s
, a
) {
229 return ( RShift( s
, a
) );