What does y -= m < 3 mean?

m < 3 is either 1 or 0, depending on the truth value.

So y=y-1 when m<3 is true, or y=y-0 when m>=3


If you break it down by order of precedence for each operation, you get:

y = (y - (m < 3));

m < 3 gets evaluated and returns a boolean result 1 or 0, so the expression can be simplified as

y = y - 1; // if m < 3 is true

or

y = y - 0; // if m < 3 is false

The purpose for doing this is to avoid an if clause.


I means if (m < 3) { y -=1; }, since (m < 3) is 1 if m is less than 3, 0 otherwise.

The code appears in some hoary old reference implementation of something to do with either leap years or Easter, or possibly both: the first two months January and February are special because they occur before the leap day. There isn't really any excuse for writing code like that, unless you actually like the look of it. Most people don't.


m < 3 evaluates to 1 if m is less than 3. Hence, y is decreased by one in this case. Thus, an if statement avoided.