octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #43753] datevec returns negative dates with in


From: Avinoam Kalma
Subject: [Octave-bug-tracker] [bug #43753] datevec returns negative dates with integer datenum
Date: Thu, 04 Dec 2014 20:58:30 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36

Follow-up Comment #2, bug #43753 (project octave):

Hi,

Maybe a better solution is to use another variable for double(date):


    date0 = double(date);
    date0 = date0(:);

    ## Move day 0 from midnight -0001-12-31 to midnight 0000-3-1
    z = floor (date0) - 60;
    ## Calculate number of centuries; K1 = 0.25 is to avoid rounding
problems.
    a = floor ((z - 0.25) / 36524.25);
    ## Days within century; K2 = 0.25 is to avoid rounding problems.
    b = z - 0.25 + a - floor (a / 4);
    ## Calculate the year (year starts on March 1).
    y = floor (b / 365.25);
    ## Calculate day in year.
    c = fix (b - floor (365.25 * y)) + 1;
    ## Calculate month in year.
    m = fix ((5 * c + 456) / 153);
    d = c - fix ((153 * m - 457) / 5);
    ## Move to Jan 1 as start of year.
    ++y(m > 12);
    m(m > 12) -= 12;

    ## Convert hour-minute-seconds.  Attempt to account for precision of
    ## datenum format.

    fracd = date0 - floor (date0);
    tmps = abs (eps*86400*date0);


Avinoam

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?43753>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]