Mercurial > hg > octave-lyh
comparison scripts/general/num2str.m @ 6997:6d0d8d621532
[project @ 2007-10-10 16:41:16 by jwe]
author | jwe |
---|---|
date | Wed, 10 Oct 2007 16:41:16 +0000 |
parents | 0d11a12643f1 |
children | 93c65f2a5668 |
comparison
equal
deleted
inserted
replaced
6996:9861dc5f382b | 6997:6d0d8d621532 |
---|---|
51 endif | 51 endif |
52 endif | 52 endif |
53 else | 53 else |
54 ## Setup a suitable format string | 54 ## Setup a suitable format string |
55 if (isnumeric (x) && round (x) == x && abs (x) < 1e10) | 55 if (isnumeric (x) && round (x) == x && abs (x) < 1e10) |
56 dgt1 = ceil (log10 (max (max (abs (real (x(:)))), | 56 if (max (abs (real (x(:)))) == 0) |
57 max (abs (imag (x(:))))))) + 1; | 57 dgt1 = 2; |
58 else | |
59 dgt1 = ceil (log10 (max (max (abs (real (x(:)))), | |
60 max (abs (imag (x(:))))))) + 2; | |
61 endif | |
58 dgt2 = dgt1 - (min (real (x(:))) >= 0); | 62 dgt2 = dgt1 - (min (real (x(:))) >= 0); |
59 | 63 |
60 if (length (abs (x) == x) > 0) | 64 if (length (abs (x) == x) > 0) |
61 fmt = sprintf("%%%dg%%+-%dgi ", dgt2, dgt1); | 65 fmt = sprintf("%%%dg%%+-%dgi ", dgt2, dgt1); |
62 else | 66 else |
119 endif | 123 endif |
120 endif | 124 endif |
121 else | 125 else |
122 if (isnumeric (x) && round (x) == x && abs (x) < 1e10) | 126 if (isnumeric (x) && round (x) == x && abs (x) < 1e10) |
123 if (max (abs (x(:))) == 0) | 127 if (max (abs (x(:))) == 0) |
124 dgt = 1; | 128 dgt = 2; |
125 else | 129 else |
126 dgt = floor (log10 (max (abs(x(:))))) + (min (real (x(:))) < 0) + 1; | 130 dgt = floor (log10 (max (abs(x(:))))) + (min (real (x(:))) < 0) + 2; |
127 endif | 131 endif |
128 if (length (abs (x) == x) > 0) | 132 if (length (abs (x) == x) > 0) |
129 fmt = sprintf ("%%%dg ", dgt); | 133 fmt = sprintf ("%%%dg ", dgt); |
130 else | 134 else |
131 fmt = sprintf ("%%%dd ", dgt); | 135 fmt = sprintf ("%%%dd ", dgt); |