[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Leap year algorithm needed



Oh, no... look what I've started ;-)

David Wilson wrote:

> stever@gate.net (Steve Reeves) writes:
>
> >In article <37137073.81146F30@ix.netcom.com>, Nick wrote:
> >>if(!(year % 400) || (!(year % 4) && (year %100))) thisyear=leapyear;
>
> >Its a little more efficient to do the division by 4 first:
>
> >if (!(year % 4) && ((year % 100) || !(year % 400))) is_leap_year = TRUE;
>
> But do not forget to set is_leap_year = FALSE before the above code...
>
> Alternatively:
>
> is_leap_year = (!(year % 4) && ((year % 100) || !(year % 400)));
>
> or
>
> is_leap_year = year % 4 ? 0 : (year % 100 ? 1 : (year % 400) ? 0 : 1);
> --
> David Wilson  School of IT & CS, Uni of Wollongong, Australia  david@uow.edu.au