Gregorian Calendar Leap Year

Started by Robert, September 26, 2025, 07:28:27 PM

Previous topic - Next topic

MrBcx

#2
There's more than one way to skin a cat ...

MACRO imod_op = %
FOR LONG year = 1600 TO 2400 STEP 100
    PRINT year, "is ";
    IF NOT ((year BAND 3) = 0 AND ((year imod_op 25) <> 0 OR (year BAND 15) = 0)) THEN
        PRINT "not ";
    END IF
    PRINT "a Leap Year"
NEXT


And just like that, the development of BCX 8.3.0 has begun.  I improved the processing of IMOD,
so it can be used as an operator and also a function. This means 8.3.0 will allow this syntax:

IF NOT ((year BAND 3) = 0 AND ((year IMOD 25) <> 0 OR (year BAND 15) = 0)) THEN



Robert

FOR INTEGER ALoop = 1600 TO 2400 STEP 100
CALL Gregorian(ALoop)
NEXT ALoop

SUB Gregorian(Year)
IF ISTRUE((ISZERO(Year BAND 3)) AND (((ISTRUE(IMOD(Year, 25))) OR (ISZERO(Year BAND 12))))) THEN
PRINT Year, "is a Leap Year."
ELSE
PRINT Year, "is not a Leap Year."
END IF
END SUB

The above is an inefficient BCX adaptation of efficient C code, by Kevin P. Rice, modified by Charles Plager, discussed at
https://stackoverflow.com/questions/3220163/how-to-find-leap-year-programmatically-in-c/11595914#11595914