How do you calculate the Julian-Gregorian conversion from 4713BC to 16000AD?

Most books give the conversion from Julian Date (JD) to Gregorian date as follows:

Add 0.5 to the JD.
Set I = integer part of JD
Set F = fractional part of JD
If I is larger than 2299160 calculate:
    A = integer part of ( I - 1867216.25)/36524.25
    B = I + 1 + A - integer part of (A/4)
otherwise, set A = I
Now calculate C = B + 1524
Calculate D = integer part of (C - 122.1)/365.25
Calculate E = integer part of 365.25 x D
Calculate G = integer part of ( C - E)/30.6001
Calculate d = C - E + F - integer part of (30.6001 x G)
     This is the day of the month including its decimal fraction
Calculate m = G - 1 if G is less than 13.5
      or m = G - 13 if G is more than 13.5
     This is the month number
Calculate y = D - 4716 if m is more than 2.5
          y = D - 4715 if m is less than 2.5
      This is the year.

Copyright 1997 Dr. Sten Odenwald
Return to Ask the Astronomer.