Mercurial > hg > octave-nkf
changeset 11784:5667eafad9a1 release-3-0-x
rat.m: handle arrays and all-integer inputs
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Jun 2008 14:21:06 -0400 |
parents | 7d9711bd4298 |
children | 35d5c824f1eb |
files | scripts/ChangeLog scripts/general/rat.m |
diffstat | 2 files changed, 20 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,9 @@ +2008-06-11 John W. Eaton <jwe@octave.org> + + * general/rat.m: Properly initialize steps when all elements of + input array are integers. Append spaces as necessary when + building character array. + 2008-06-04 Bill Denney <bill@denney.ws> * time/weekday.m: Allow vector inputs and speed up.
--- a/scripts/general/rat.m +++ b/scripts/general/rat.m @@ -64,8 +64,13 @@ ## grab new factors until all continued fractions converge while (1) ## determine which fractions have not yet converged - idx = find (abs(y-n./d) >= tol); - if (isempty(idx)) break; endif + idx = find(abs (y-n./d) >= tol); + if (isempty(idx)) + if (isempty (steps)) + steps = NaN .* ones (nsz, 1); + endif + break; + endif ## grab the next step in the continued fraction flip = 1./frac(idx); @@ -128,6 +133,13 @@ endif endwhile s = [s, repmat(")", 1, j-2)]; + n_nc = columns (n); + s_nc = columns (s); + if (n_nc > s_nc) + s(:,s_nc+1:n_nc) = " " + elseif (s_nc > n_nc) + n(:,n_nc+1:s_nc) = " "; + endif n = cat (1, n, s); endfor endif