changeset 31343:121b24b3a224

maint: Merge stable to default.
author Arun Giridhar <arungiridhar@gmail.com>
date Tue, 25 Oct 2022 13:30:17 -0400
parents e3365fd1bd06 (current diff) 7880af7a3b3f (diff)
children d446c9076928
files scripts/strings/dec2bin.m
diffstat 1 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/strings/dec2bin.m	Tue Oct 25 10:15:28 2022 -0700
+++ b/scripts/strings/dec2bin.m	Tue Oct 25 13:30:17 2022 -0400
@@ -56,13 +56,11 @@
 ## @end example
 ##
 ## Known @sc{matlab} Incompatibility: @sc{matlab}'s @code{dec2bin} allows
-## non-integer values for @var{d}, truncating the value using the equivalent
-## of @code{fix (@var{d})} for positive values, but, as of R2020b and in
-## conflict with published documentation, appears to use
-## @code{round (@var{d})} for negative values.  To be consistent with
-## @code{dec2hex} and @code{dec2base}, Octave produces an error for non-integer
-## valued inputs for @var{d}.  Users wanting compatible code for non-integer
-## valued inputs should make use of @code{fix} or @code{round} as appropriate.
+## non-integer values for @var{d} as of Release 2022b, but is inconsistent
+## with truncation versus rounding and is also inconsistent with its own
+## @code{dec2hex} function.  For self-consistency, Octave gives an error for
+## non-integer inputs.  Users requiring compatible code for non-integer inputs
+## should make use of @code{fix} or @code{round} as appropriate.
 ## @seealso{bin2dec, dec2base, dec2hex}
 ## @end deftypefn
 
@@ -75,6 +73,11 @@
   if (iscell (d))
     d = cell2mat (d);
   endif
+
+  if (! isnumeric (d) || iscomplex (d) || any (d(:) != round (d(:))))
+    error ("dec2bin: input must be integers");
+  endif
+
   ## Create column vector for algorithm (output is always col. vector anyways)
   d = d(:);
 
@@ -150,3 +153,9 @@
 
 ## Test input validation
 %!error <Invalid call> dec2bin ()
+%!error <input must be integer> dec2bin (+2.1)
+%!error <input must be integer> dec2bin (-2.1)
+%!error <input must be integer> dec2bin (+2.9)
+%!error <input must be integer> dec2bin (-2.9)
+%!error <input must be integer> dec2bin (1+i)
+