In a recent note, john gilmore said:

> Date:         Tue, 13 Sep 2005 03:22:10 +0000
> 
> There is no need to use a simplified or 'linear'  leap-year correction
> calculation.  For any algebraic Gregorian year value y the exact signed
> number of leap-year correction days in preceding years is easily calculated
> by the method of inclusions and exclusions.  It is just
> 
> C(y) = 365(y - 1)
>   + (y - 1)//4
>   -  (y - 1)//100
>   + (y - 1)//400
> 
> in which '//' denotes remainder-discarding binary-integer division.
> 
In fact, this returns the total number of days, not the number of
leap-year correction days.

"Algebraic" and "signed" imply the formula gives correct results
for negative years, assuming the Gregorian calendar is so extrapolated
backwards.  The formula works correctly only if "//" truncates
toward negative infinity, not toward zero.

And it can be simplified to (the less referentially transparent):

    C(y) = (y - 1) * 146097 // 400

-- gil
-- 
StorageTek
INFORMATION made POWERFUL

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

Reply via email to