Mercurial > hg > octave-nkf
changeset 15732:82b0ad43a939
num2str: Take into account inf inputs. Add tests for inf and NaN
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 05 Dec 2012 16:53:53 -0500 |
parents | 18f168880226 |
children | 628011b1bd2f |
files | scripts/general/num2str.m |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/num2str.m +++ b/scripts/general/num2str.m @@ -83,8 +83,14 @@ endif else if (isnumeric (x)) - ## Setup a suitable format string - dgt = floor (log10 (max (abs (x(:))))); + ## Setup a suitable format string, ignoring inf entries + dgt = floor (log10 (max (abs (x(!isinf (x(:))))))); + + ## If the whole input array is inf... + if (isempty (dgt)) + dgt = 0; + endif + if (any (x(:) != fix (x(:)))) ## Floating point input dgt = max (dgt + 4, 5); # Keep 4 sig. figures after decimal point @@ -169,6 +175,8 @@ %!assert (num2str (-2^33), "-8589934592") %!assert (num2str (2^33+1i), "8589934592+1i") %!assert (num2str (-2^33+1i), "-8589934592+1i") +%!assert (num2str (inf), "Inf") +%!assert (num2str (nan), "NaN") ## FIXME: Integers greater than bitmax() should be masked to show just ## 16 digits of precision.