year_is_leap_year = (YEAR >= 1583) & (YEAR < 4909) & (mod(YEAR,4) == 0) & ((mod(YEAR,400) == 0) | (mod(YEAR,100) ~= 0));
Unless, that is, you are calculating for England or any possession of England including USA, in which case the 1583 needs to be changed to 1753.
The 4909 year is the latest year by which there will need to be a correction because the current system has a year approximately 26 seconds too long.