![]() ![]() ![]() This would throw us out of whack, for example affecting timing of seasons we are all used to. However, as time passed, our calendar would lose touch with the Earth’s position in the Solar system. We could say the difference is minimal and for a few years, you could get away without leap years. So, 365 days is a bit short and 366 days too long to account for a year. It is this quarter of a day extra which means we occasionally need to add in an extra day to the year. In other words, about 365 and a quarter days. The Earth rotates just a little over 365 times per year!ģ65.242375 times to be more exact. In fact, they have been around for over 2000 years.įirst added by Julius Caesar in 46BC at the advice of Sosigenes, an astronomer, leap years have proven to be quite useful.Ī year means the period of time it takes for the Earth to rotate around the sun.Ī day means the period of time it takes Earth to rotate around its axis once.Īnd now comes the important detail. We use calendars to track and organise time and days.Īnd much like calendars, leap years are a human construct to assist us in tracking time. Having leap years helps us to keep time effectively. So it had an extra day in February.Ĭonversely, 2019 or 2021, are common years and hence not leap years. ![]() On the other hand, years that are not leap years (common years) have 365 days.Īs an example, 2020 is a leap year. 4 How can I know which years are leap years?īy definition, a leap year is a year that has 366 days in the calendar.Is_leap_year 2004 is # a leap year # Save the above to a file named is_leap_year.sh, then issue the following command to run the 5 tests of the function # bash is_leap_year.sh BASIC Applesoft BASIC Ī one-liner combination from the Commodore BASIC and GW-BASIC solutions. year and test's expectation for 'is/not leap year. Is_leap_year () # Define function named is_leap_year # test all cases # call the function is_leap_year several times with two parameters. function Is_Leap_Year ( Year : Integer ) return Boolean is begin return ( Year rem 4 = 0 ) and then (( Year rem 16 = 0 ) or else ( Year rem 100 /= 0 )) end Is_Leap_Year - To improve speed a bit more, use with pragma Inline ( Is_Leap_Year ) ALGOL 60 If a year evenly divisible by 100 => not a leap year. If a year is evenly divisible by 16, it is either evenly divisible by 400 or - not evenly divisible by 100 => leap year. If a year is not divisible by 4 => not a leap year. Ergo, the - set of integers evenly divisible by 16 and 100 are all evenly divisible by 400. FYI: 400 is evenly divisible by 16 whereas 100,200 and 300 are not. I failed to be convinced of the accuracy of the algorithm at first, - so I rephrased it below. It then checks rem 16 (a 4 bit comparison), and only if those are not - conclusive, calls rem 100, which is the most expensive operation. function Is_Leap_Year ( Year : Integer ) return Boolean is begin if Year rem 100 = 0 then return Year rem 400 = 0 else return Year rem 4 = 0 end if end Is_Leap_Year - An enhanced, more efficient version: - This version only does the 2 bit comparison (rem 4) if false. Adjust the type of Year if you use a different one. Incomplete code, just a sniplet to do the task. Test: lxi b,5Dh First char of "file name" Test code: get year from CP/M command line and see Output: Carry flag set if HL is a leap year. IF RETURN-CODE = ZERO DISPLAY YEAR-VALUE ' IS A LEAP YEAR'ĮLSE DISPLAY YEAR-VALUE ' IS NOT A LEAP YEAR'. LR 15,0 LOAD REMAINDER: IF 0, THEN LEAP YEAR SRDL 0,32 NO: R0|R1 = YY CCYY NOT DIV BY 100, TEST YYĪ LA 2,4 DIVISOR = 4 DIVIDEND = YY, OR DIV BY 100 CCĭR 0,2 DIVIDE BY 4: R0 = REMAINDER, R1 = QUOTIENT LTR 0,0 YY = 0? IF CCYY DIV BY 100, LY IFF DIV BY 400īZ A YES: R0|R1 = CC CCYY DIV BY 100, TEST CC PACK 0(8,2),0(4,1) PACK CCYY INTO WORK AREAĭR 0,2 DIVIDE CCYY BY 100: R0 = YY, R1 = CC LM 1,2,0(1) R1 -> CCYY, R2 -> DOUBLE-WORD WORK AREA
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |