SmallInteger.st
branchjv
changeset 17844 29a1536dffe4
parent 17841 7abcc4aef871
child 17845 7e0cfaac936d
--- a/SmallInteger.st	Thu Jun 09 16:28:45 2011 +0100
+++ b/SmallInteger.st	Thu Jun 23 16:55:10 2011 +0100
@@ -794,7 +794,6 @@
     "
 ! !
 
-
 !SmallInteger methodsFor:'bit operators'!
 
 bitAnd:anInteger
@@ -3840,6 +3839,30 @@
     ^ super even
 !
 
+isPowerOfTwo
+    "return true, if the receiver is a power of 2"
+
+"/ mhmh: how about the following
+"/    self == 0 ifTrue:[^ false].
+
+    ^ (self bitAnd:(self - 1)) == 0
+
+    "
+     0 isPowerOfTwo
+     1 isPowerOfTwo
+     2 isPowerOfTwo
+     3 isPowerOfTwo                   
+     4 isPowerOfTwo                   
+     16r8000000000000000 isPowerOfTwo   
+     16r8000000000000001 isPowerOfTwo   
+
+     10000 factorial isPowerOfTwo
+     |n| n := 10000 factorial. Time millisecondsToRun:[1000 timesRepeat:[ n isPowerOfTwo]] 
+    "
+
+    "Modified: / 20-06-2011 / 12:41:18 / cg"
+!
+
 negative
     "return true, if the receiver is less than zero
      reimplemented here for speed"
@@ -3922,15 +3945,15 @@
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Id: SmallInteger.st 10643 2011-06-08 21:53:07Z vranyj1 $'
+    ^ '$Id: SmallInteger.st 10648 2011-06-23 15:55:10Z vranyj1 $'
 !
 
 version_CVS
-    ^ 'Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.187 2010/08/09 17:52:27 cg Exp '
+    ^ 'Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.188 2011/06/20 10:41:39 cg Exp '
 !
 
 version_SVN
-    ^ '$Id: SmallInteger.st 10643 2011-06-08 21:53:07Z vranyj1 $'
+    ^ '$Id: SmallInteger.st 10648 2011-06-23 15:55:10Z vranyj1 $'
 ! !
 
 
@@ -3942,3 +3965,4 @@
 
 
 
+