Rename QDeclarative symbols to QQuick and QQml
[profile/ivi/qtdeclarative.git] / tests / auto / qml / parserstress / tests / ecma / Expressions / 11.7.1.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 gTestfile = '11.7.1.js';
40
41 /**
42    File Name:          11.7.1.js
43    ECMA Section:       11.7.1 The Left Shift Operator ( << )
44    Description:
45    Performs a bitwise left shift operation on the left argument by the amount
46    specified by the right argument.
47
48    The production ShiftExpression : ShiftExpression << AdditiveExpression is
49    evaluated as follows:
50
51    1.  Evaluate ShiftExpression.
52    2.  Call GetValue(Result(1)).
53    3.  Evaluate AdditiveExpression.
54    4.  Call GetValue(Result(3)).
55    5.  Call ToInt32(Result(2)).
56    6.  Call ToUint32(Result(4)).
57    7.  Mask out all but the least significant 5 bits of Result(6), that is,
58    compute Result(6) & 0x1F.
59    8.  Left shift Result(5) by Result(7) bits. The result is a signed 32 bit
60    integer.
61    9.  Return Result(8).
62
63    Author:             christine@netscape.com
64    Date:               12 november 1997
65 */
66 var SECTION = "11.7.1";
67 var VERSION = "ECMA_1";
68 startTest();
69
70 writeHeaderToLog( SECTION + " The left shift operator ( << )");
71
72 for ( power = 0; power < 33; power++ ) {
73   shiftexp = Math.pow( 2, power );
74
75   for ( addexp = 0; addexp < 33; addexp++ ) {
76     new TestCase( SECTION,
77                   shiftexp + " << " + addexp,
78                   LeftShift( shiftexp, addexp ),
79                   shiftexp << addexp );
80   }
81 }
82
83 test();
84
85 function ToInteger( n ) {
86   n = Number( n );
87   var sign = ( n < 0 ) ? -1 : 1;
88
89   if ( n != n ) {
90     return 0;
91   }
92   if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY ) {
93     return n;
94   }
95   return ( sign * Math.floor(Math.abs(n)) );
96 }
97 function ToInt32( n ) {
98   n = Number( n );
99   var sign = ( n < 0 ) ? -1 : 1;
100
101   if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
102     return 0;
103   }
104
105   n = (sign * Math.floor( Math.abs(n) )) % Math.pow(2,32);
106   n = ( n >= Math.pow(2,31) ) ? n - Math.pow(2,32) : n;
107
108   return ( n );
109 }
110 function ToUint32( n ) {
111   n = Number( n );
112   var sign = ( n < 0 ) ? -1 : 1;
113
114   if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
115     return 0;
116   }
117   n = sign * Math.floor( Math.abs(n) )
118
119     n = n % Math.pow(2,32);
120
121   if ( n < 0 ){
122     n += Math.pow(2,32);
123   }
124
125   return ( n );
126 }
127 function ToUint16( n ) {
128   var sign = ( n < 0 ) ? -1 : 1;
129
130   if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
131     return 0;
132   }
133
134   n = ( sign * Math.floor( Math.abs(n) ) ) % Math.pow(2,16);
135
136   if (n <0) {
137     n += Math.pow(2,16);
138   }
139
140   return ( n );
141 }
142 function Mask( b, n ) {
143   b = ToUint32BitString( b );
144   b = b.substring( b.length - n );
145   b = ToUint32Decimal( b );
146   return ( b );
147 }
148 function ToUint32BitString( n ) {
149   var b = "";
150   for ( p = 31; p >=0; p-- ) {
151     if ( n >= Math.pow(2,p) ) {
152       b += "1";
153       n -= Math.pow(2,p);
154     } else {
155       b += "0";
156     }
157   }
158   return b;
159 }
160 function ToInt32BitString( n ) {
161   var b = "";
162   var sign = ( n < 0 ) ? -1 : 1;
163
164   b += ( sign == 1 ) ? "0" : "1";
165
166   for ( p = 30; p >=0; p-- ) {
167     if ( (sign == 1 ) ? sign * n >= Math.pow(2,p) : sign * n > Math.pow(2,p) ) {
168       b += ( sign == 1 ) ? "1" : "0";
169       n -= sign * Math.pow( 2, p );
170     } else {
171       b += ( sign == 1 ) ? "0" : "1";
172     }
173   }
174
175   return b;
176 }
177 function ToInt32Decimal( bin ) {
178   var r = 0;
179   var sign;
180
181   if ( Number(bin.charAt(0)) == 0 ) {
182     sign = 1;
183     r = 0;
184   } else {
185     sign = -1;
186     r = -(Math.pow(2,31));
187   }
188
189   for ( var j = 0; j < 31; j++ ) {
190     r += Math.pow( 2, j ) * Number(bin.charAt(31-j));
191   }
192
193   return r;
194 }
195 function ToUint32Decimal( bin ) {
196   var r = 0;
197
198
199   for ( l = bin.length; l < 32; l++ ) {
200     bin = "0" + bin;
201   }
202
203   for ( j = 0; j < 31; j++ ) {
204     r += Math.pow( 2, j ) * Number(bin.charAt(31-j));
205
206   }
207
208   return r;
209 }
210 function LeftShift( s, a ) {
211   var shift = ToInt32( s );
212   var add = ToUint32( a );
213   add = Mask( add, 5 );
214   var exp = LShift( shift, add );
215
216   return ( exp );
217 }
218 function LShift( s, a ) {
219   s = ToInt32BitString( s );
220
221   for ( var z = 0; z < a; z++ ) {
222     s += "0";
223   }
224
225   s = s.substring( a, s.length);
226
227   return ToInt32(ToInt32Decimal(s));
228 }