changeset 6997:6d0d8d621532

[project @ 2007-10-10 16:41:16 by jwe]
author jwe
date Wed, 10 Oct 2007 16:41:16 +0000
parents 9861dc5f382b
children cc049a392a97
files scripts/ChangeLog scripts/general/num2str.m
diffstat 2 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Wed Oct 10 00:39:22 2007 +0000
+++ b/scripts/ChangeLog	Wed Oct 10 16:41:16 2007 +0000
@@ -1,3 +1,8 @@
+2007-10-10  John W. Eaton  <jwe@octave.org>
+
+	* general/num2str.m: Always allow for sign for automatically
+	computed format widths.
+
 2007-10-09  David Bateman  <dbateman@free.fr>
 
 	* plot/patch.m: Accept a handle as the first argument.
--- a/scripts/general/num2str.m	Wed Oct 10 00:39:22 2007 +0000
+++ b/scripts/general/num2str.m	Wed Oct 10 16:41:16 2007 +0000
@@ -53,8 +53,12 @@
     else
       ## Setup a suitable format string
       if (isnumeric (x) && round (x) == x && abs (x) < 1e10)
-	dgt1 = ceil (log10 (max (max (abs (real (x(:)))),
-				 max (abs (imag (x(:))))))) + 1;
+	if (max (abs (real (x(:)))) == 0)
+	  dgt1 = 2;
+	else
+	  dgt1 = ceil (log10 (max (max (abs (real (x(:)))),
+				   max (abs (imag (x(:))))))) + 2;
+	endif
 	dgt2 = dgt1 - (min (real (x(:))) >= 0);
 	
 	if (length (abs (x) == x) > 0)
@@ -121,9 +125,9 @@
     else
       if (isnumeric (x) && round (x) == x && abs (x) < 1e10)
 	if (max (abs (x(:))) == 0)
-	  dgt = 1;
+	  dgt = 2;
 	else
-	  dgt = floor (log10 (max (abs(x(:))))) + (min (real (x(:))) < 0) + 1;
+	  dgt = floor (log10 (max (abs(x(:))))) + (min (real (x(:))) < 0) + 2;
 	endif
 	if (length (abs (x) == x) > 0)
 	  fmt = sprintf ("%%%dg  ", dgt);