changeset 16773:3542e106c496

dec2base.m: treat logical as double for compatibility with ML (bug #38815).
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Sun, 28 Apr 2013 22:12:20 +0200
parents 7eff3032d144
children 8d188159ce5f
files scripts/strings/dec2base.m
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/strings/dec2base.m	Tue Jun 18 20:35:12 2013 -0700
+++ b/scripts/strings/dec2base.m	Sun Apr 28 22:12:20 2013 +0200
@@ -66,8 +66,11 @@
   if (! iscolumn (d))
     d = d(:);
   endif
-
-  if (! isnumeric (d) || iscomplex (d) || any (d < 0 | d != fix (d)))
+  
+  ## Treat logical as numeric for compatibility with ML
+  if (islogical (d))
+    d = double (d);
+  elseif (! isnumeric (d) || iscomplex (d) || any (d < 0 | d != fix (d)))
     error ("dec2base: input must be real non-negative integers");
   endif
 
@@ -151,6 +154,10 @@
 %!assert (dec2base ([1, 2; 3, 4], 2, 3), ["001"; "011"; "010"; "100"])
 %!assert (dec2base ({1, 2; 3, 4}, 2, 3), ["001"; "011"; "010"; "100"])
 
+%!test
+%! a = 0:3;
+%! assert (dec2base (!a, 2, 1), ["1"; "0"; "0"; "0"])
+
 %%Test input validation
 %!error dec2base ()
 %!error dec2base (1)