#OTHER
authorClaus Gittinger <cg@exept.de>
Wed, 20 Jan 2016 13:21:19 +0100
changeset 19058 12a9089fbc5e
parent 19057 a1eb8bcc42d2
child 19059 687547192a05
#OTHER class: Integer comment/format in: #isPowerOf: #nextPowerOf2 changed: #isPerfectSquare FIX: 0 is a perfect square
Integer.st
--- a/Integer.st	Wed Jan 20 13:16:18 2016 +0100
+++ b/Integer.st	Wed Jan 20 13:21:19 2016 +0100
@@ -4086,6 +4086,7 @@
     |intSqrt realSqrt|
     
     self strictlyPositive ifFalse:[
+        self == 0 ifTrue:[^ true].
         "/ should we raise a domain error for negative receivers?
         ^ false
     ].
@@ -4096,7 +4097,8 @@
     ].        
     self < 1024 ifTrue:[    
         ^ #(400 441 484 529 576 625 676 729 784 841 900 961) includes:self.
-    ].        
+    ].
+    
     "/ try powers of 2
     self isPowerOfTwo ifTrue:[
         ^ self lowBit odd
@@ -4117,6 +4119,10 @@
     ^ intSqrt squared = self
 
     "
+     0 isPerfectSquare
+     3 isPerfectSquare
+     4 isPerfectSquare
+     9 isPerfectSquare
      (1 to:1000000) count:[:n | n isPerfectSquare] 1000
      12345678987654321234567 isPerfectSquare
      123123123432 squared isPerfectSquare
@@ -4139,6 +4145,9 @@
         onError:-1) isPowerOfTwo
 
     "
+     0 isPowerOf:2
+     1 isPowerOf:2
+     
      16r0000000000000000 isPowerOf:2
      16r0000004000000000 isPowerOf:2
      16r0000004000000001 isPowerOf:2
@@ -4268,7 +4277,9 @@
 nextPowerOf2
     "return the power of 2 at or above the receiver.
      Useful for padding.
-     Notice, that for a powerOf2, the receiver is returned."
+     Notice, that for a powerOf2, the receiver is returned.
+     Also notice, that (because it is used for padding), 
+     0 is returned for zero."
 
     |x t sh|
 
@@ -4288,6 +4299,7 @@
     ^ x + 1 
 
     "
+     0 nextPowerOf2    
      1 nextPowerOf2    
      2 nextPowerOf2    
      3 nextPowerOf2