Mercurial > octave
changeset 29880:dbc191149841
num2str.m: Also fix integer input with second input argument.
* scripts/general/num2str.m: Don't print integer input with a format string for
floating point numbers. Add test with an integer that can't be represented in
double precision.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Wed, 14 Jul 2021 17:33:02 +0200 |
parents | ca30a6c1acc3 |
children | 35155423c0ef |
files | scripts/general/num2str.m |
diffstat | 1 files changed, 6 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/num2str.m Wed Jul 14 16:14:49 2021 +0200 +++ b/scripts/general/num2str.m Wed Jul 14 17:33:02 2021 +0200 @@ -95,7 +95,11 @@ if (ischar (arg)) fmt = arg; elseif (isnumeric (arg) && isscalar (arg) && arg >= 0 && arg == fix (arg)) - fmt = sprintf ("%%%d.%dg", arg+7, arg); + if (isfloat (x)) + fmt = sprintf ("%%%d.%dg", arg+7, arg); + else + fmt = sprintf ("%%%dd", arg); + endif else error ("num2str: PRECISION must be a scalar integer >= 0"); endif @@ -225,6 +229,7 @@ %!assert (num2str (complex (NA, 1)), "NA+1i") %!assert (num2str (complex (1, NA)), "1+NAi") %!assert (num2str (int64 (-flintmax ()) - 1), "-9007199254740993") +%!assert (num2str (int64 (-flintmax ()) - 1, 18), "-9007199254740993") ## ND-arrays are concatenated in columns %!shared m, x