# HG changeset patch # User Arun Giridhar # Date 1666719017 14400 # Node ID 121b24b3a224af32cee63bcd4aacfb41725c012f # Parent e3365fd1bd06b82002c5d7192af21a551dcddd89# Parent 7880af7a3b3f496a27d1a98498c75bd6ee806d1b maint: Merge stable to default. diff -r e3365fd1bd06 -r 121b24b3a224 scripts/strings/dec2bin.m --- 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 dec2bin () +%!error dec2bin (+2.1) +%!error dec2bin (-2.1) +%!error dec2bin (+2.9) +%!error dec2bin (-2.9) +%!error dec2bin (1+i) +