I feel compelled to point out that in the Gregorian calendar (which I believe you're using) there is no year zero.

Therefore you are going to need to alter the equations to counter for the fact that AD0/BC0 doesn't actually exist. ie -40+80=41