#DOCUMENTATION by cg
authorClaus Gittinger <cg@exept.de>
Mon, 27 May 2019 08:49:19 +0200
changeset 24168 7b016046fdb9
parent 24167 0dc1e390b3e0
child 24169 db5c25cc1e42
#DOCUMENTATION by cg class: SmallInteger changed: #highBit
SmallInteger.st
--- a/SmallInteger.st	Mon May 27 08:49:02 2019 +0200
+++ b/SmallInteger.st	Mon May 27 08:49:19 2019 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1988 by Claus Gittinger
 	      All Rights Reserved
@@ -1968,36 +1966,38 @@
 highBit
     "return the bitIndex of the highest bit set.
      The returned bitIndex starts at 1 for the least significant bit.
-     Returns 0 if no bit is set."
+     Returns 0 if no bit is set.
+     Notice for negative numbers, the returned value is undefined (actually: nonsense),
+     because for 2's complement representation, conceptionally all high bits are 1"
 
 %{  /* NOCONTEXT */
 #ifdef __SCHTEAM__
     {
-	long bits = self.longValue();
-	int bitNr = 0;
-
-	if (bits != 0) {
-	    if ((bits & 0xFFFFFFFF00000000L) != 0) {
-		bitNr += 32; bits >>= 32;
-	    }
-	    if ((bits & 0xFFFF0000L) != 0) {
-		bitNr += 16; bits >>= 16;
-	    }
-	    if ((bits & 0xFF00) != 0) {
-		bitNr += 8; bits >>= 8;
-	    }
-	    if ((bits & 0xF0) != 0) {
-		bitNr += 4; bits >>= 4;
-	    }
-	    if ((bits & 0xC) != 0) {
-		bitNr += 2; bits >>= 2;
-	    }
-	    if ((bits & 0x2) != 0) {
-		bitNr += 1; bits >>= 1;
-	    }
-	    bitNr += 1;
-	}
-	return context._RETURN( STInteger._new(bitNr) );
+        long bits = self.longValue();
+        int bitNr = 0;
+
+        if (bits != 0) {
+            if ((bits & 0xFFFFFFFF00000000L) != 0) {
+                bitNr += 32; bits >>= 32;
+            }
+            if ((bits & 0xFFFF0000L) != 0) {
+                bitNr += 16; bits >>= 16;
+            }
+            if ((bits & 0xFF00) != 0) {
+                bitNr += 8; bits >>= 8;
+            }
+            if ((bits & 0xF0) != 0) {
+                bitNr += 4; bits >>= 4;
+            }
+            if ((bits & 0xC) != 0) {
+                bitNr += 2; bits >>= 2;
+            }
+            if ((bits & 0x2) != 0) {
+                bitNr += 1; bits >>= 1;
+            }
+            bitNr += 1;
+        }
+        return context._RETURN( STInteger._new(bitNr) );
     }
     /* NOTREACHED */
 #else
@@ -2023,8 +2023,8 @@
      */
 #  if (POINTER_SIZE == 4) && defined( USE_IEE_FLOAT_BITS )
     union {
-	double ff;
-	int ll[2];
+        double ff;
+        int ll[2];
     } uu;
     int bNr;
 
@@ -2042,27 +2042,27 @@
 
     bits = __intVal(self);
     if (bits == 0) {
-	RETURN ( __mkSmallInteger(0) );
+        RETURN ( __mkSmallInteger(0) );
     }
 #  if __POINTER_SIZE__ == 8
     if (bits & 0xFFFFFFFF00000000L) {
-	index += 32; bits >>= 32;
+        index += 32; bits >>= 32;
     }
 #  endif
     if (bits & 0xFFFF0000L) {
-	index += 16; bits >>= 16;
+        index += 16; bits >>= 16;
     }
     if (bits & 0xFF00) {
-	index += 8; bits >>= 8;
+        index += 8; bits >>= 8;
     }
     if (bits & 0xF0) {
-	index += 4; bits >>= 4;
+        index += 4; bits >>= 4;
     }
     if (bits & 0xC) {
-	index += 2; bits >>= 2;
+        index += 2; bits >>= 2;
     }
     if (bits & 0x2) {
-	index += 1; bits >>= 1;
+        index += 1; bits >>= 1;
     }
 #  endif /* not IEE float */
 # endif /* no BSR instruction */
@@ -2081,38 +2081,38 @@
      2r100000000000 highBit
 
      ((0 to:64) collect:[:s | 1 bitShift:s])
-	collect:[:n | n highBit]
+        collect:[:n | n highBit]
 
      (((0 to:64) collect:[:s | 1 bitShift:s])
-	collect:[:n | n highBit]) = (1 to:65)
+        collect:[:n | n highBit]) = (1 to:65)
     "
 
     "
      Time millisecondsToRun:[
-	1000000 timesRepeat:[
-	    2r1 highBit
-	]
+        1000000 timesRepeat:[
+            2r1 highBit
+        ]
      ]
     "
     "
      Time millisecondsToRun:[
-	1000000 timesRepeat:[
-	    2r1111 highBit
-	]
+        1000000 timesRepeat:[
+            2r1111 highBit
+        ]
      ]
     "
     "
      Time millisecondsToRun:[
-	1000000 timesRepeat:[
-	    2r11111111111111 highBit
-	]
+        1000000 timesRepeat:[
+            2r11111111111111 highBit
+        ]
      ]
     "
     "
      Time millisecondsToRun:[
-	1000000 timesRepeat:[
-	    2r11111111111111111111111111 highBit
-	]
+        1000000 timesRepeat:[
+            2r11111111111111111111111111 highBit
+        ]
      ]
     "
 
@@ -2125,6 +2125,7 @@
     "
 
     "Modified: / 05-07-2017 / 16:56:08 / cg"
+    "Modified: / 27-05-2019 / 08:48:39 / Claus Gittinger"
 !
 
 lowBit