Prev: int32_Ttricore_add_s32_s32_s32_sat(int32_Ta,int32_Tb)
Next: *****online/offline job vacancy's send your cv *****
From: osmium on 1 Apr 2010 06:00 lachman(a)ebony.ppc.ubc.ca wrote: > TEXAS TWO-STEP CALCULATION OF THE WEEKDAY FOR ALL DAYS > 00040301-42461231 - using Hans Lachman's Method of Congruence as > optimised below - > > > Strictly adhering to Lachman's Maxim (Complexity is a diseconomy of > scale), this method was designed to run sublimely as a stand-alone > function, when your only recourse is to call a 68k ASM program via > AMS on TI calculators: i.e. no values looked up in tables, files or > libraries when executing, no kernel, no system calls, no exception > processing, minimal registers to be used, nor the need to save any. > It is valid for (historical) Julian dates as of 1.iii.IV and for > Gregorian ones from 1.iii.MCM to 29.ii.MMCC. > > Although using a processor more sophisticated than found on > four-function calculators, this method is simpler to execute than > Hans' original Method of Congruence needing manipulation of data by > numerically competent users. It succeeds where other Methods do not > when computing the day of the week even on the lowliest 68k device: > having no need of extra instructions for data stored in tables as in > Babwani's Method nor for redundant operations as in Zeller's or > Tondering's; yet executing in less than two dozen lines. > > > The function below returns the corresponding ISO-compatible weekday > number, when called with 3 inputs loaded from the following > locations: > > ; WDN, an address for storing result d0 > ; FLAG, to choose between sets of calendars (93 or 94 here) > ; DATE, basic ISO format YYYYMMDD date-stamp as binary word&byte&byte > ; > movem.l DATE,d0,d2 > move.l FLAG,d1 > lea WDN,a0 > ; > ; APPLY STEP 1 OF HANS LACHMAN'S METHOD OF CONGRUENCE > andi.l #$0000ff00,d2 > divu #100,d2 > add.w d2,d1 > divu #100,d1 > swap d1 ; D1.W CONTAINS THE MonthIndex > ; > ; APPLY STEP 2 > move.l d0,d2 > add.b d2,d1 > swap d2 > add.w d2,d1 > subi.l #$00000300,d0 > movi.l #$00000012,d2 > lsr d2,d0 > add.w d1,d0 > divu #7,d0 > swap d0 ; D0.W CONTAINS THE WEEKDAY NUMBER > ; > ; RETURN THE WEEKDAY NUMBER TO LOCATION WDN > move.b d0,(a0) > rts > ; > ; Days of the week correspond to weekday numbers as: > ; Sun=0 Mon=1 Tue=2 Wed=3 Thu=4 Fri=5 Sat=6 > > The code is streamlined such that parameters are to be passed to it in > proper format. For example, one must pass a flag of 94 for Gregorian > dates as of 1.iii.MCM until 29.ii.MMC, and 93 from 1.iii.MMC until > 29.ii.MMCC; as well as 93 for (historical) Julian dates where years > start on 1.i, and years divisible by 4 are leap years. Some historians > claim that IV A.D. was not a leap year, so that a flag of 93 thereby > applies for Julian dates only as of 1.iii.IV. It applies till Julian > 29.ii.MCM--a valid date for Orthodox countries like Russia & Greece. > This function thereby gives compleat valid historical continuity of > date conversion for SOMEWHERE on the planet for all days from 1.iii.IV > to 29.ii.MMCC. Otherwise, it still gives valid conversions for Julian > dates on the Orthodox calendar until 31.xii.MMMMCCXLVI A.D.
From: lachman on 3 Apr 2010 21:39
[N. B.: This revision uses the constant 94 and 0=Sun, and adds further parameters to cover all valid Gregorian dates. Please post comments, if any, via Usenet or via ccnet. Thanks.] HOW TO CALCULATE THE DAY OF THE WEEK FOR DATES AS OF 15.x.1582 based on Hans' No-Sweat 1-Off 2-Fold 3-Step 4-Function Calculator Method This is a more involved method to calculate the day of the week for Gregorian calendar dates from 15.x.1582 and as far into the future as workable using standard four-function calculators and certain mobile phones via a generalised formula requiring fewer key-clicks than any previous method not using tables. Given: Day.Month.Year as a Date on the Gregorian calendar as of 15.octob.1582 & YLJLD as the 'Year in which the Last Julian Leap Day occurred' prior to the given Date as if for a Julian Calendar whose years begin on 1.jan. & delta = Year - YLJLD & Century as a nominal "age" for each hundred of years as of 1.march.XY00 (only one lag Offset thereby required for an entire Gregorian Century) so that if YLJLD = XYQR, then Century = XY (starting with Century 15) & yljld as the last two digits of XYQR, such that yljld = QR & under as the number of years that Century is less than the next higher multiple of 4; one can convert the given Date into a day of the week after completing the 3 steps below--with 33 key-clicks or less, without any mental multiplication or division. STEP 0. Calculate the lag Offset: under * 2 Remember the result or store it in memory. STEP 1. Calculate the given Date's MonthIndex: Month * 2.56 + 94 and then drop the fraction, and the hundreds digit, if any, to get an integer less than 100, e.g. 124.72 becomes 24; remember the result for use in Step 2. STEP 2. Apply the generalised date conversion formula: (yljld/.8 + delta + MonthIndex + Day + Offset) / 7 STEP 3. Apply Hans' keypad mapping: Take the first digit after the decimal point (if none, use 0) and map that to a day using the following patterns: +-----+-----+-----+ +-----+-----+-----+ | Fri | Sat | | | 1 | 2 | 3 | | 7 | 8 | 9 | | Mon | Tue | | +-----+-----+-----+ +-----+-----+-----+ | Wed | Thu | | | 4 | 5 | 6 | | 4 | 5 | 6 | | Wed | Thu | | +-----+-----+-----+ +-----+-----+-----+ | Mon | Tue | | | 7 | 8 | 9 | | 1 | 2 | 3 | | Fri | Sat | | +-----+-----+-----+ +-----+-----+-----+ | Sun | | 0 | | 0 | | Sun | +-----+ +-----+ (This is equivalent to assigning days to remainders of divisions by 7 as for: Sun=0 Mon=1 Tue=2 Wed=3 Thu=4 Fri=5 Sat=6.) Lag is the number of days that a Gregorian date to be converted falls before the same Julian date. It was zero for Century 02, during which the Gregorian Calendar, if already implemented beforehand, would have been the same as the Julian--thus leading to Hans' Julian Step 2 formula. It must be decreased by 1 for every March 1st preceded by February 29th in the Julian but not in the Gregorian calendar. Lag is now -13 and will be -14 as of 1.iii.MMC to start off Century 21 when Hans' shorter Julian formula applies again to Gregorian dates, the last time being in Centuries 11 & 12 when it was -7 in both. In Century 00 as of 1.iii.IV, it was +2. EXAMPLE Z. 29.Feb.1904 Century = 19 yljld = 00 delta = 4 under = 1 1 * 2 = 2 2 * 2.56 + 94 = 99.12 (MonthIndex = 99) 00/.8 + 4 + 99 + 29 + 2 Divide by 7 = 19.142857... first decimal = 1 Day of Week = Mon EXAMPLE A. 31.Dec.2100 Century = 21 yljld = 00 delta = 0 under = 3 3 * 2 = 6 12 * 2.56 + 94 = 124.72 (MonthIndex = 24) 00/.8 + 0 + 24 + 31 + 6 Divide by 7 = 8.714285... first decimal = 7 Day of Week = Fri EXAMPLE B. 29.Feb.2000 Century = 19 yljld = 96 delta = 4 under = 1 1 * 2 = 2 2 * 2.56 + 94 = 99.12 (MonthIndex = 99) 96/.8 + 4 + 99 + 29 + 2 Divide by 7 = 36.285714... first decimal = 2 Day of Week = Tue EXAMPLE C. 1.Mar.2000 Century = 20 yljld = 00 delta = 0 under = 4 4 * 2 = 8 3 * 2.56 + 94 = 101.28 (MonthIndex = 1) 00/.8 + 0 + 1 + 1 + 8 Divide by 7 = 1.428571... first decimal = 4 Day of Week = Wed The Examples above are for a standard (running total) calculator; those for RPN or algebraic calculators are left as an exercise. (Hint: re-order Steps and streamline operations.) -- REFERENCES: http://oz.ccnet.us/dayofweek/ http://groups.google.com/group/sci.math/msg/a716e5ca3af3ed28 |