changeset 21455:9d1a5b22e87a

powerset.m: Fix for big-endian systems * powerset.m: Fix construction of set combinations on big-endian systems.
author Mike Miller <mtmiller@octave.org>
date Wed, 16 Mar 2016 20:22:17 -0700
parents ebd93e63b48e
children c1c7748b00fe
files scripts/set/powerset.m
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/set/powerset.m	Wed Mar 16 00:17:10 2016 -0400
+++ b/scripts/set/powerset.m	Wed Mar 16 20:22:17 2016 -0700
@@ -68,7 +68,12 @@
     endif
 
     ## Logical rep
-    b = reshape (bitunpack (uint32 (0:2^n-1)), 32, 2^n)(1:n,:);
+    m = uint32 (0:2^n-1);
+    ## FIXME: better test for endianness?
+    if (bitunpack (uint16 (1))(1) == 0)
+      m = swapbytes (m);
+    endif
+    b = reshape (bitunpack (m), 32, 2^n)(1:n,:);
     ## Convert to indices and lengths.
     [i, k] = find (b);
     k = sum (b, 1);