Debian Codegraph @

rhino/testsrc/tests/ecma/Expressions/11.4.8.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = '11.4.8.js';
7
8 /**
9 File Name: 11.4.8.js
10 ECMA Section: 11.4.8 Bitwise NOT Operator
11 Description: flip bits up to 32 bits
12 no special cases
13 Author: [email protected]
14 Date: 7 july 1997
15
16 Data File Fields:
17 VALUE value passed as an argument to the ~ operator
18 E_RESULT expected return value of ~ VALUE;
19
20 Static variables:
21 none
22
23 */
24
25 var SECTION = "11.4.8";
26 var VERSION = "ECMA_1";
27 startTest();
28
29 writeHeaderToLog( SECTION + " Bitwise Not operator");
30
31 for ( var i = 0; i < 35; i++ ) {
32 var p = Math.pow(2,i);
33
34 new TestCase( SECTION, "~"+p, Not(p), ~p );
35
36 }
37 for ( i = 0; i < 35; i++ ) {
38 var p = -Math.pow(2,i);
39
40 new TestCase( SECTION, "~"+p, Not(p), ~p );
41
42 }
43
44 test();
45
46 function ToInteger( n ) {
47 n = Number( n );
48 var sign = ( n < 0 ) ? -1 : 1;
49
50 if ( n != n ) {
51 return 0;
52 }
53 if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY ) {
54 return n;
55 }
56 return ( sign * Math.floor(Math.abs(n)) );
57 }
58 function ToInt32( n ) {
59 n = Number( n );
60 var sign = ( n < 0 ) ? -1 : 1;
61
62 if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
63 return 0;
64 }
65
66 n = (sign * Math.floor( Math.abs(n) )) % Math.pow(2,32);
67 n = ( n >= Math.pow(2,31) ) ? n - Math.pow(2,32) : n;
68
69 return ( n );
70 }
71 function ToUint32( n ) {
72 n = Number( n );
73 var sign = ( n < 0 ) ? -1 : 1;
74
75 if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
76 return 0;
77 }
78 n = sign * Math.floor( Math.abs(n) )
79
80 n = n % Math.pow(2,32);
81
82 if ( n < 0 ){
83 n += Math.pow(2,32);
84 }
85
86 return ( n );
87 }
88 function ToUint16( n ) {
89 var sign = ( n < 0 ) ? -1 : 1;
90
91 if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
92 return 0;
93 }
94
95 n = ( sign * Math.floor( Math.abs(n) ) ) % Math.pow(2,16);
96
97 if (n <0) {
98 n += Math.pow(2,16);
99 }
100
101 return ( n );
102 }
103 function Mask( b, n ) {
104 b = ToUint32BitString( b );
105 b = b.substring( b.length - n );
106 b = ToUint32Decimal( b );
107 return ( b );
108 }
109 function ToUint32BitString( n ) {
110 var b = "";
111 for ( var p = 31; p >=0; p-- ) {
112 if ( n >= Math.pow(2,p) ) {
113 b += "1";
114 n -= Math.pow(2,p);
115 } else {
116 b += "0";
117 }
118 }
119 return b;
120 }
121 function ToInt32BitString( n ) {
122 var b = "";
123 var sign = ( n < 0 ) ? -1 : 1;
124
125 b += ( sign == 1 ) ? "0" : "1";
126
127 for ( var p = 30; p >=0; p-- ) {
128 if ( (sign == 1 ) ? sign * n >= Math.pow(2,p) : sign * n > Math.pow(2,p) ) {
129 b += ( sign == 1 ) ? "1" : "0";
130 n -= sign * Math.pow( 2, p );
131 } else {
132 b += ( sign == 1 ) ? "0" : "1";
133 }
134 }
135
136 return b;
137 }
138 function ToInt32Decimal( bin ) {
139 var r = 0;
140 var sign;
141
142 if ( Number(bin.charAt(0)) == 0 ) {
143 sign = 1;
144 r = 0;
145 } else {
146 sign = -1;
147 r = -(Math.pow(2,31));
148 }
149
150 for ( var j = 0; j < 31; j++ ) {
151 r += Math.pow( 2, j ) * Number(bin.charAt(31-j));
152 }
153
154 return r;
155 }
156 function ToUint32Decimal( bin ) {
157 var r = 0;
158
159 for ( var l = bin.length; l < 32; l++ ) {
160 bin = "0" + bin;
161 }
162
163 for ( var j = 0; j < 31; j++ ) {
164 r += Math.pow( 2, j ) * Number(bin.charAt(31-j));
165 }
166
167 return r;
168 }
169 function Not( n ) {
170 n = ToInt32(n);
171 n = ToInt32BitString(n);
172
173 var r = "";
174
175 for( var l = 0; l < n.length; l++ ) {
176 r += ( n.charAt(l) == "0" ) ? "1" : "0";
177 }
178
179 n = ToInt32Decimal(r);
180
181 return n;
182 }