Number of Days After January 1
|
03-14-2019, 07:20 PM
Post: #4
|
|||
|
|||
RE: Number of Days After January 1
(03-11-2019 02:25 AM)Eddie W. Shore Wrote: If M = 1 and M = 2 Then Eddie, you can simplify these formulas significantly. Since D and 400 are positive integers... int(30.6 * M + 368.8) + D - 400 = int(30.6 * M + 368.8 + D - 400) = int(30.6 * M + D - 31.2) Or here (D=1 or 2) simply = int(30.6 * M + D - 31) The two other formulas can be simplified the same way. Or they can be derived from the Jan/Feb formula. With L=0 (common year) or 1 (leap year): days = 30.6 * M + D - 31 if M >= 3 then days = days - 2.3 + L return int(days) Note: according to your formulas the final 2.3 would be 2.4, but subtracting only 2.3 leaves a fractional part between 0.1 and 0.9 so that roundoff problems are avoided (e.g. in non-decimal environments) that may lead to cases like int(242.9999999....) for 1 September. Here is a version of your HP-41C program that implements this idea. Code: 01 LBL "DAYD" XEQ "DAYD" MONTH↑DAY ? 10 [ENTER] 1 [R/S] LEAP YR 0/1? 0 [R/S] => 273 Note that the program only prompts for a leap year input if this is required, i.e. for months between March and December. Dieter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Number of Days After January 1 - Eddie W. Shore - 03-11-2019, 02:25 AM
RE: Number of Days After January 1 - Dieter - 03-11-2019, 06:53 PM
Number of Days After March 1st - Thomas Klemm - 03-11-2019, 08:30 PM
RE: Number of Days After January 1 - Dieter - 03-14-2019 07:20 PM
|
User(s) browsing this thread: 1 Guest(s)