Slimelite BBS

Re: Pcc

Back to R25C

From George White · 1996-04-02 05:47 · #75183 in R25C

In reply to Pcc by Bill Birrell

Hi Ian,

You wrote to Damian Walker:

IJA>>Many people's understanding of leap years is that they fall upon every yea
IJA>>divisible by four except those which are divisible by *300*, not 100.  Tha
IJA>>makes the years 1900 and 2000 a leap year, and 1800 and 2100 not.

IJA>Which is of course wrong, since 1900 wasn't a leap year.

I think he'll get that message from the number of responses he's
getting!

IJA>In the Gregorian calendar, a year is a leap year if and only if it is
IJA>divisible by 400, or if it is divisible by 4 but not by 100.

IJA>leap = (year%400 == 0 || (year%4 == 0 && year%100 != 0));

Now I'll try to teach Grandmother to suck eggs :-)

Which is better expressed with the 400 year test last rather than first
because the logical logic operators (&&, ||) are evaluated left to right
and evaluation ends as soon as the logical truth of the expression can
be determined. So the test is best expressed as

if (year%4 == 0 && year%100 != 0 || year%400 == 0)
    leap = TRUE;
else
    leap = FALSE;

to give the minimum amount of testing.
It is the expression Kernigan and Richie use in the example of the
use of the modulus operator "%" (Section 2.5 in the first ed).

George

 * SLMR 2.1a * if (pot.coffee == EMPTY) { programmer->brain = OFF };

--- Maximus/2 3.01
 * Origin: DoNoR/2,Woking UK (44-1483-725167)  (2:440/4)