# HG changeset patch # User John W. Eaton # Date 1213208466 14400 # Node ID 5667eafad9a10018293cadc10dfb9351cb9996ae # Parent 7d9711bd4298846ec8c2af1f5757b915e55f3230 rat.m: handle arrays and all-integer inputs diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,9 @@ +2008-06-11 John W. Eaton + + * 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 * time/weekday.m: Allow vector inputs and speed up. diff --git a/scripts/general/rat.m b/scripts/general/rat.m --- 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