Mercurial > octave
changeset 29879:ca30a6c1acc3
num2str.m: Don't convert integer input to floating point.
* 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 16:14:49 +0200 |
parents | 2cc14e275a51 |
children | dbc191149841 |
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 11:47:25 2021 +0200 +++ b/scripts/general/num2str.m Wed Jul 14 16:14:49 2021 +0200 @@ -119,7 +119,11 @@ if (any (! valid)) ndgt = max (ndgt, 5); # Allow space for Inf/NaN endif - fmt = sprintf ("%%%d.0f", ndgt); + if (isfloat (x)) + fmt = sprintf ("%%%d.0f", ndgt); + else + fmt = sprintf ("%%%dd", ndgt); + endif endif else ## Logical input @@ -220,6 +224,7 @@ %!assert (num2str (NA), "NA") %!assert (num2str (complex (NA, 1)), "NA+1i") %!assert (num2str (complex (1, NA)), "1+NAi") +%!assert (num2str (int64 (-flintmax ()) - 1), "-9007199254740993") ## ND-arrays are concatenated in columns %!shared m, x