SmallInteger.st
changeset 8334 4466f66d1f9a
parent 7746 4a4208ef7699
child 8365 69e253fc6a95
--- a/SmallInteger.st	Fri Apr 23 18:11:23 2004 +0200
+++ b/SmallInteger.st	Tue Apr 27 14:29:44 2004 +0200
@@ -811,27 +811,33 @@
     "(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2"
 !
 
-bitAt:index
+bitAt:anIntegerIndex
     "return the value of the index's bit (index starts at 1).
      Notice: the result of bitAt: on negative receivers is not 
              defined in the language standard (since the implementation
              is free to choose any internal representation for integers)"
 
-    |mask|
-
-    index <= 0 ifTrue:[
-        ^ SubscriptOutOfBoundsSignal 
-                raiseRequestWith:index
-                errorString:'index out of bounds'
-    ].
-    (index > SmallInteger maxBits) ifTrue:[^ 0].
-    mask := 1 bitShift:(index - 1).
-    ((self bitAnd:mask) == 0) ifTrue:[^ 0].
-    ^ 1
+%{  /* NOCONTEXT */
+
+    if (__isSmallInteger(anIntegerIndex)) {
+        INT idx = __smallIntegerVal(anIntegerIndex);
+        if (idx > 0) {
+            if (idx > N_INT_BITS) {
+                RETURN(__mkSmallInteger(0));
+            }
+            RETURN((__smallIntegerVal(self) & (1 << (idx-1))) ? __mkSmallInteger(1) : __mkSmallInteger(0));
+        }
+    }
+%}.
+
+    ^ SubscriptOutOfBoundsSignal 
+            raiseRequestWith:anIntegerIndex
+            errorString:'index out of bounds'
 
     "
      16r00000001 bitAt:0
      16r00000001 bitAt:1 
+     16r00000001 bitAt:2 
      16r00008000 bitAt:16 
      16r00800000 bitAt:24 
      16r08000000 bitAt:28 
@@ -841,6 +847,20 @@
      16r80000000 bitAt:32 
      16r100000000 bitAt:33 
     "
+
+" Smalltalk implementation:
+    |mask|
+
+    anIntegerIndex <= 0 ifTrue:[
+        ^ SubscriptOutOfBoundsSignal 
+                raiseRequestWith:anIntegerIndex
+                errorString:'index out of bounds'
+    ].
+    (anIntegerIndex > SmallInteger maxBits) ifTrue:[^ 0].
+    mask := 1 bitShift:(anIntegerIndex - 1).
+    ((self bitAnd:mask) == 0) ifTrue:[^ 0].
+    ^ 1
+"
 !
 
 bitClear:anInteger
@@ -3376,5 +3396,5 @@
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.156 2003-11-11 13:16:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.157 2004-04-27 12:29:41 stefan Exp $'
 ! !