[leap year] うるう年の判別
例1
y=年(整数)
n = (1 / (y % 4 + 1)) * (1 - 1 / (y % 100 + 1)) + (1 / (y % 400 + 1))
n=1 ==>うるう年
n=0 ==>うるう年
a % bはa - a / b * bで表せる
例2
n = (1 / (y - y / 4 * 4 + 1)) * (1 - 1 / (y - y / 100 * 100 + 1)) + (1 / (y - y / 400 * 400 + 1))
整数の割り算が割り切れない場合、切り捨てられる
1 / (y % 4 + 1)はyが4の倍数の場合のみ1になる
例3
LOGICAL FUNCTION LEAPYR(Y)
INTEGER Y
LEAPYR=.FALSE.
IF(MOD(Y,4).NE.0) RETURN
IF((MOD(Y,100).EQ.0).AND.(MOD(Y,400).NE.0)) RETURN
LEAPYR=.TRUE.
END
C====================================
C
C Which years are leap years?
C http://www.timeanddate.com/date/leapyear.html
C
C====================================
C
C In the Gregorian calendar, which is the calendar used by most modern
C countries, the following rules decides which years are leap years:
C
C 1. Every year divisible by 4 is a leap year.
C 2. But every year divisible by 100 is NOT a leap year
C 3. Unless the year is also divisible by 400, then it is still
C a leap year.
C
C This means that year 1800, 1900, 2100, 2200, 2300 and 2500 are **NOT**
C leap years, while year 2000 and 2400 are leap years.
C
C This actually means year 2000 is kind of special, as it is the first
C time the third rule is used in many parts of the world.
C
C In the old Julian Calendar, there was only one rule: Every year
C divisible by 4 is a leap year. This calendar was used before the
C Gregorian calendar was adopted.