[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 2.9.15 --> 3.0
From: |
John Swensen |
Subject: |
Re: 2.9.15 --> 3.0 |
Date: |
Wed, 10 Oct 2007 08:26:24 -0400 |
User-agent: |
Thunderbird 2.0.0.6 (Macintosh/20070728) |
John W. Eaton wrote:
I applied the patch, which seems to fix the problem of extra space in
the output. We still have
| 2) num2str doesn't account for signed zeros while mat2str does:
|
| octave-2.9.13.exe:50> num2str(-0,10)
| ans = 0
| octave-2.9.13.exe:51> mat2str(-0,10)
| ans = -0
I haven't looked closely, but mat2str is also a .m file, so I think
num2str shoudl also be able to ahndle -0 without any changes to the
C++ bits of Octave.
Thanks,
jwe
I'm pretty sure the patch I submitted also fixes the problem with not
accounting for -0.
octave:1> a = -0
a = -0
octave:2> num2str(a) ans = -0
octave:3> A = repmat(a,5,5)
A =
-0 -0 -0 -0 -0
-0 -0 -0 -0 -0
-0 -0 -0 -0 -0
-0 -0 -0 -0 -0
-0 -0 -0 -0 -0
octave:4> num2str(A)
ans =
-0 -0 -0 -0 -0
-0 -0 -0 -0 -0
-0 -0 -0 -0 -0
-0 -0 -0 -0 -0
-0 -0 -0 -0 -0
Here is a patch with the parenthesis spacing as requested (maybe you
already did this before applying the patch).
John Swensen
Index: scripts/general/num2str.m
===================================================================
RCS file: /cvs/octave/scripts/general/num2str.m,v
retrieving revision 1.30
diff -u -r1.30 num2str.m
--- scripts/general/num2str.m 20 Apr 2007 18:16:08 -0000 1.30
+++ scripts/general/num2str.m 8 Oct 2007 01:03:07 -0000
@@ -56,11 +56,16 @@
dgt1 = ceil (log10 (max (max (abs (real (x(:)))),
max (abs (imag (x(:))))))) + 1;
dgt2 = dgt1 - (min (real (x(:))) >= 0);
- fmt = sprintf("%%%dd%%+-%ddi ", dgt2, dgt1);
+
+ if (length (abs (x) == x) > 0 )
+ fmt = sprintf("%%%dg%%+-%dgi ", dgt2, dgt1);
+ else
+ fmt = sprintf("%%%dd%%+-%ddi ", dgt2, dgt1);
+ endif
elseif (isscalar (x))
- fmt = "%.4g%-+.4gi";
+ fmt = "%.6g%-+.6gi";
else
- fmt = "%11.4g%-+11.4gi";
+ fmt = "%11.6g%-+11.6gi";
endif
endif
@@ -101,7 +106,7 @@
endwhile
tmp(length (tmp)) = "";
- retval = split (tmp, "\n");
+ retval = strtrim (split (tmp, "\n"));
else
if (nargin == 2)
if (ischar (arg))
@@ -120,18 +125,22 @@
else
dgt = floor (log10 (max (abs(x(:))))) + (min (real (x(:))) < 0) + 1;
endif
- fmt = sprintf ("%%%dd ", dgt);
+ if (length (abs (x) == x) > 0 )
+ fmt = sprintf ("%%%dg ", dgt);
+ else
+ fmt = sprintf ("%%%dd ", dgt);
+ endif
elseif (isscalar (x))
- fmt = "%.4g";
+ fmt = "%11.5g";
else
- fmt = "%11.4g";
+ fmt = "%11.5g";
endif
endif
fmt = strcat (deblank (repmat (fmt, 1, columns (x))), "\n");
nd = ndims (x);
tmp = sprintf (fmt, permute (x, [2, 1, 3:nd]));
tmp(length (tmp)) = "";
- retval = split (tmp, "\n");
+ retval = strtrim (split (tmp, "\n") );
endif
endfunction
- Re: 2.9.15 --> 3.0, (continued)
Re: 2.9.15 --> 3.0, Rafael Laboissiere, 2007/10/07
Re: 2.9.15 --> 3.0, John Swensen, 2007/10/07
Re: 2.9.15 --> 3.0, David Bateman, 2007/10/08
2.9.15 --> 3.0, John W. Eaton, 2007/10/12