Calendar Functions (simpler leap year calculation)

Daniel R. Levy levy at ttrdc.UUCP
Wed Sep 17 09:34:50 AEST 1986


In article <34 at vianet.UUCP>, devine at vianet.UUCP (Bob Devine) writes:
>Dave Lewis writes:
>> leapyear (year)
>> int year;
>> {
>>   if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
>>      return (1);
>>   else
>>      return (0);
>> }
>
>  While this works, it is overkill.  Unless you believe that your
>code will make it to the year 2100, a simple test for divisibility
>by 4 is sufficient.  If you really want an algorithm for all years,
>you then need to also test for years divisible by 4000...
>
...
>
>#define  isleapyear(year)   ((year)%4)
>
>Bob Devine

Butbutbut... whattabout code which deals with things that are of concern
over more than a few years' scope, such as positions of the heavenly bodies?
The code needn't last till the year 2100 to want to deal with things that
are going to happen then (only the printouts :-) ).  And what about birth
dates of very old people?
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
	   go for it!  			allegra,ulysses,vax135}!ttrdc!levy



More information about the Comp.lang.c mailing list