@@ -124,5 +124,76 @@ throw e;
124124}
125125return result ;
126126} , "~S" ) ;
127+ //sgurin compare and compareTo. the same implementation as in Integer
128+ Long . compare = Clazz . defineMethod ( Long , "compare" ,
129+ function ( f1 , f2 ) {
130+ if ( f1 < f2 ) return - 1 ;
131+ if ( f1 > f2 ) return 1 ;
132+ return 0 ;
133+ } , "~N,~N" ) ;
134+ Long . prototype . compareTo = function ( anotherInt ) {
135+ var otherValue = anotherInt ;
136+ if ( anotherInt . valueOf ) otherValue = anotherInt . valueOf ( ) ;
137+ return java . lang . Long . compare ( this . valueOf ( ) , otherValue ) ;
138+ }
139+ //sgurin bitwise related static methods
140+ Long . bitCount = Clazz . defineMethod ( Long , "bitCount" , function ( i ) {
141+ i = i - ( ( i >>> 1 ) & 0x5555555555555555 ) ;
142+ i = ( i & 0x3333333333333333 ) + ( ( i >>> 2 ) & 0x3333333333333333 ) ;
143+ i = ( i + ( i >>> 4 ) ) & 0x0f0f0f0f0f0f0f0f ;
144+ i = i + ( i >>> 8 ) ;
145+ i = i + ( i >>> 16 ) ;
146+ i = i + ( i >>> 32 ) ;
147+ return i & 0x7f ;
148+ } , "~N" ) ;
149+ Long . rotateLeft = Clazz . defineMethod ( Long , "rotateLeft" , function ( i , distance ) {
150+ return ( i << distance ) | ( i >>> - distance ) ;
151+ } , "~N,~N" ) ;
152+ Long . rotateRight = Clazz . defineMethod ( Long , "rotateRight" , function ( i , distance ) {
153+ return ( i >>> distance ) | ( i << - distance ) ;
154+ } , "~N,~N" ) ;
155+ Long . highestOneBit = Clazz . defineMethod ( Long , "highestOneBit" , function ( i ) {
156+ i |= ( i >> 1 ) ; i |= ( i >> 2 ) ; i |= ( i >> 4 ) ;
157+ i |= ( i >> 8 ) ; i |= ( i >> 16 ) ; i |= ( i >> 32 ) ;
158+ return i - ( i >>> 1 ) ;
159+ } , "~N" ) ;
160+ Long . lowestOneBit = Clazz . defineMethod ( Long , "lowestOneBit" , function ( i ) {
161+ return i & - i ; } , "~N" ) ;
162+ Long . numberOfLeadingZeros = Clazz . defineMethod ( Long , "numberOfLeadingZeros" , function ( i ) {
163+ if ( i == 0 ) return 64 ;
164+ var n = 1 ; var x = ( i >>> 32 ) ;
165+ if ( x == 0 ) { n += 32 ; x = i ; }
166+ if ( x >>> 16 == 0 ) { n += 16 ; x <<= 16 ; }
167+ if ( x >>> 24 == 0 ) { n += 8 ; x <<= 8 ; }
168+ if ( x >>> 28 == 0 ) { n += 4 ; x <<= 4 ; }
169+ if ( x >>> 30 == 0 ) { n += 2 ; x <<= 2 ; }
170+ n -= x >>> 31 ; return n ; } , "~N" ) ;
171+ Long . numberOfTrailingZeros = Clazz . defineMethod ( Long , "numberOfTrailingZeros" , function ( i ) {
172+ var x ; var y ;
173+ if ( i == 0 ) return 64 ;
174+ var n = 63 ; y = i ;
175+ if ( y != 0 ) { n = n - 32 ; x = y ; }
176+ else x = ( i >>> 32 ) ;
177+ y = x << 16 ;
178+ if ( y != 0 ) { n = n - 16 ; x = y ; }
179+ y = x << 8 ;
180+ if ( y != 0 ) { n = n - 8 ; x = y ;
181+ } y = x << 4 ;
182+ if ( y != 0 ) { n = n - 4 ; x = y ;
183+ } y = x << 2 ;
184+ if ( y != 0 ) { n = n - 2 ; x = y ;
185+ } return n - ( ( x << 1 ) >>> 31 ) ; } , "~N" ) ;
186+ Long . signum = Clazz . defineMethod ( Long , "signum" , function ( i ) {
187+ return ( ( i >> 63 ) | ( - i >>> 63 ) ) ; } , "~N" ) ;
188+ Long . reverseBytes = Clazz . defineMethod ( Long , "reverseBytes" , function ( i ) {
189+ i = ( i & 0x00ff00ff00ff00ff ) << 8 | ( i >>> 8 ) & 0x00ff00ff00ff00ff ;
190+ return ( i << 48 ) | ( ( i & 0xffff0000 ) << 16 ) | ( ( i >>> 16 ) & 0xffff0000 ) | ( i >>> 48 ) ; } , "~N" ) ;
191+ Long . reverse = Clazz . defineMethod ( Long , "reverse" , function ( i ) {
192+ i = ( i & 0x5555555555555555 ) << 1 | ( i >>> 1 ) & 0x5555555555555555 ;
193+ i = ( i & 0x3333333333333333 ) << 2 | ( i >>> 2 ) & 0x3333333333333333 ;
194+ i = ( i & 0x0f0f0f0f0f0f0f0f ) << 4 | ( i >>> 4 ) & 0x0f0f0f0f0f0f0f0f ;
195+ i = ( i & 0x00ff00ff00ff00ff ) << 8 | ( i >>> 8 ) & 0x00ff00ff00ff00ff ;
196+ i = ( i << 48 ) | ( ( i & 0xffff0000 ) << 16 ) | ( ( i >>> 16 ) & 0xffff0000 ) | ( i >>> 48 ) ;
197+ return i ; } , "~N" ) ;
127198} ) ;
128199
0 commit comments