# HG changeset patch # User Markus Mützel # Date 1626276782 -7200 # Node ID dbc191149841f9456863b76b8c29bd7b5dbf9e08 # Parent ca30a6c1acc36407cc542a6865a9d2472932a662 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. diff -r ca30a6c1acc3 -r dbc191149841 scripts/general/num2str.m --- 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