On 01/11/2010 05:21 PM, Gunnar Opheim wrote: > ----- Original Message ----- > From: "john gilmore" <john_w_gilm...@msn.com> > Newsgroups: bit.listserv.ibm-main > To: <IBM-MAIN@bama.ua.edu> > Sent: Monday, January 11, 2010 9:20 PM > Subject: Re: Bad leap-year code > > >> >> It is certainly true, as Joel C. Ewing contends, that bad leap-year code > abounds. Unfortunately, it is also true that the assorted TM-based schemes he > has presented in a sequence of posts are bad too, even radically misconceived. > > The scheme with two TM tests works perfectly for the years 1901-2099, and > nobody > has claimed that it works continuously outside this range. > I would have thought it was clear from the full context of this discussion that I disparaged the "TM" approach and only attempted to supply code in response to conjecture on the required instruction count, not as a recommendation on its use. The fact that I almost immediately had to report an error in my code re-enforces that this is an overly clever and potentially dangerous implementation choice.
The same double-TM approach that works for the determining whether the lower two digits are divisible by 4 could certainly be applied to the upper two digits to determine if the century digits are divisible by 4, and thus extend this approach to correctly mirror a more conventional approach for all years in the range 1582-9999 - but that still doesn't make it an advisable scheme to use because of the lack of clarity and the much greater difficulty of proving code correctness. -- Joel C. Ewing, Fort Smith, AR jremoveccapsew...@acm.org ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html