#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Mon, 28 Aug 2017 19:30:52 +0200
changeset 22222 d58f6ee4f7fc
parent 22221 ffeed1814b34
child 22223 579090043bea
#FEATURE by cg class: Integer comment/format in: #bitDeinterleave: changed: #bitInterleaveWith: #bitInterleaveWith:and:
Integer.st
--- a/Integer.st	Mon Aug 28 19:30:44 2017 +0200
+++ b/Integer.st	Mon Aug 28 19:30:52 2017 +0200
@@ -1662,14 +1662,14 @@
 
 bitDeinterleave:n
     "extract count integers from an n-way Morton number as a vector;
+     This is the inverse operation from bitInterleave: - see comment there.
      i.e. if count is 3,
      and the receiver's bits are
         cN bN aN ... c2 b2 a2 c1 b1 a1 c0 b0 a0
      then the result will be a vector containing the numbers a,b,c with bits:
         aN ... a2 a1 a0
         bN ... b2 b1 b0 
-        cN ... c2 c1 c0.
-     This is the inverse operation from bitInterleave:"
+        cN ... c2 c1 c0."
      
     |v shift tuple|
 
@@ -1697,6 +1697,7 @@
     "
 
     "Created: / 28-08-2017 / 15:02:31 / cg"
+    "Modified (comment): / 28-08-2017 / 18:45:21 / cg"
 !
 
 bitInterleaveWith:anInteger
@@ -1718,6 +1719,9 @@
 
     |a b shift ma mb val|
 
+    self assert:(self >= 0).
+    self assert:(a >= 0).
+
     a := self.
     b := anInteger.
     val := 0.
@@ -1747,6 +1751,7 @@
     "
 
     "Created: / 28-08-2017 / 14:33:08 / cg"
+    "Modified: / 28-08-2017 / 19:19:31 / cg"
 !
 
 bitInterleaveWith:integer1 and:integer2
@@ -1766,12 +1771,16 @@
 
     |a b c shift ma mb mc val|
 
+    self assert:(self >= 0).
+    self assert:(a >= 0).
+    self assert:(b >= 0).
+    
     a := self.
     b := integer1.
     c := integer2.
     val := 0.
     shift := 0.
-    [ (a == 0) and:[b == 0]] whileFalse:[
+    [ (a == 0) and:[b == 0] and:[c == 0] ] whileFalse:[
         "/ strip off 4 bits from each...
         "/ 0000       0001       0010       0011       0100       0101       0110       0111       1000       1001       1010       1011       1100       1101       1110       1111 
         mc := #( 2r000000000000 2r000000000100 2r000000100000 2r000000100100 2r000100000000 2r000100000100 2r000100100000 2r000100100100 2r100000000000 2r100000000100 2r100000100000 2r100000100100 2r100100000000 2r100100000100 2r100100100000 2r100100100100 ) 
@@ -1790,10 +1799,16 @@
 
     "
      (2r1100 bitInterleaveWith:2r1001 and:2r1010) printStringRadix:2 -> '111 001 100 010'
+
      (2r11000110 bitInterleaveWith:2r10011100 and:2r10100101) printStringRadix:2 -> '111 001 100 010 010 111 001 100'
+     (1 bitInterleaveWith:1 and:16)
+     
+     ((1<<31) bitInterleaveWith:(1<<31) and:(1<<31)) bitDeinterleave:3
+     ((1<<31) bitInterleaveWith:(1<<63) and:(1<<95)) bitDeinterleave:3
     "
 
     "Created: / 28-08-2017 / 14:33:04 / cg"
+    "Modified: / 28-08-2017 / 19:19:25 / cg"
 !
 
 bitInvert