# HG changeset patch # User jwe # Date 1150434099 0 # Node ID b645066d40ada3afc9c6f4d197119683e8efa59e # Parent ba0bea22167b49268248e66adf8b6bdbdda62f75 [project @ 2006-06-16 05:01:38 by jwe] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2006-06-16 John W. Eaton + + * time/datevec.m: Avoid computing log of non-positive values. + 2006-06-14 John W. Eaton * time/datevec.m: Attempt to account for precision of datenum format. diff --git a/scripts/time/datevec.m b/scripts/time/datevec.m --- a/scripts/time/datevec.m +++ b/scripts/time/datevec.m @@ -156,7 +156,10 @@ ## datenum format. fracd = date - floor (date); - srnd = 10 .^ floor (log10 (365.25*y)); + ## Special case for total days <= 0. + tmpd = abs (365.25*y); + tmpd(tmpd == 0) = 1; + srnd = 10 .^ floor (log10 (tmpd)); s = round (86400*fracd.*srnd) ./ srnd; h = floor (s / 3600); s = s - 3600 * h; @@ -300,7 +303,7 @@ %!assert(all(datenum(datevec([-1e4:1e4]))==[-1e4:1e4]')) %!test %! t = linspace (-2e5, 2e5, 10993); -%! assert (all (datenum (datevec (t)) == t')); +%! assert (all (abs (datenum (datevec (t)) - t') < 1e-5)); # demos %!demo %! datevec (now ())