SmallInteger.st
branchjv
changeset 17993 956342c369a2
parent 17951 fa0e1d7467ea
child 18011 deb0c3355881
--- a/SmallInteger.st	Wed Nov 28 10:22:05 2012 +0000
+++ b/SmallInteger.st	Fri Nov 30 17:19:23 2012 +0000
@@ -1180,10 +1180,10 @@
 
     bits = __intVal(self);
     if (bits == 0) {
-	RETURN ( __mkSmallInteger(0) );
+        RETURN ( __mkSmallInteger(0) );
     }
 
-#ifdef __BSR
+#ifdef __BSR              
     /*
      * so much for CISC CPUS:
      * the following code is not faster on a PIII-400
@@ -1196,23 +1196,23 @@
 
 # if __POINTER_SIZE__ == 8
     if (bits & 0xFFFFFFFF00000000L) {
-	index += 32; bits = bits >> 32;
+        index += 32; bits = bits >> 32;
     }
 # endif
     if (bits & 0xFFFF0000L) {
-	index += 16; bits = bits >> 16;
+        index += 16; bits = bits >> 16;
     }
     if (bits & 0xFF00) {
-	index += 8; bits = bits >> 8;
+        index += 8; bits = bits >> 8;
     }
     if (bits & 0xF0) {
-	index += 4; bits = bits >> 4;
+        index += 4; bits = bits >> 4;
     }
     if (bits & 0xC) {
-	index += 2; bits = bits >> 2;
+        index += 2; bits = bits >> 2;
     }
     if (bits & 0x2) {
-	index += 1; bits = bits >> 1;
+        index += 1; bits = bits >> 1;
     }
 #endif /* no BSR instruction */
 
@@ -1227,38 +1227,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
+        ]
      ]
     "
 
@@ -3349,34 +3349,41 @@
 !
 
 intlog10
-    "return the truncation of log10 of the receiver -
-     stupid implementation; used to find out the number of digits needed
+    "return the truncation of log10 of the receiver.
+     The same as (self log:10) floor.
+     Stupid implementation, which is used to find out the number of digits needed
      to print a number/and for conversion to a LargeInteger.
      Implemented that way, to allow for tiny systems (PDAs) without a Float class
      (i.e. without log)."
 
     self <= 0 ifTrue:[
-	^ self class
-	    raise:#domainErrorSignal
-	    receiver:self
-	    selector:#intlog10
-	    arguments:#()
-	    errorString:'logarithm of negative integer'
+        ^ self class
+            raise:#domainErrorSignal
+            receiver:self
+            selector:#intlog10
+            arguments:#()
+            errorString:'logarithm of negative integer'
     ].
-    self < 10 ifTrue:[^ 0].
-    self < 100 ifTrue:[^ 1].
-    self < 1000 ifTrue:[^ 2].
-    self < 10000 ifTrue:[^ 3].
-    self < 100000 ifTrue:[^ 4].
-    self < 1000000 ifTrue:[^ 5].
-    self < 10000000 ifTrue:[^ 6].
-    self < 100000000 ifTrue:[^ 7].
+    self < 10000 ifTrue:[
+        self < 10 ifTrue:[^ 0].
+        self < 100 ifTrue:[^ 1].
+        self < 1000 ifTrue:[^ 2].
+        ^ 3
+    ].
+    self < 100000000 ifTrue:[
+        self < 100000 ifTrue:[^ 4].
+        self < 1000000 ifTrue:[^ 5].
+        self < 10000000 ifTrue:[^ 6].
+        ^ 7
+    ].
     self < 1000000000 ifTrue:[^ 8].
     ^ 9
 
     "
       99 intlog10
-      100 intlog10
+      100 intlog10 
+      101 intlog10        
+      (101 log:10) floor  
       120 intlog10
       -1 intlog10
     "
@@ -4113,13 +4120,13 @@
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.196 2012/07/06 16:33:40 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.197 2012/11/04 15:06:59 cg Exp $'
 !
 
 version_CVS
-    ^ '§Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.196 2012/07/06 16:33:40 stefan Exp §'
+    ^ '§Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.197 2012/11/04 15:06:59 cg Exp §'
 !
 
 version_SVN
-    ^ '$Id: SmallInteger.st 10824 2012-07-18 16:55:48Z vranyj1 $'
+    ^ '$Id: SmallInteger.st 10876 2012-11-30 17:19:23Z vranyj1 $'
 ! !