Is this a leap year?
Is this a leap year?
ISLEAP is a very short and easy function to test is a year is a leap year. The main aim of this function is the use of logical operators.
As everybody knows the Gregorian calendar has 97 leap years every 400 years: every year divisible by 4 is a leap year.
However, every year divisible by 100 is not a leap year and every year divisible by 400 is a leap year after all. So, 1700, 1800, 1900, 2100, and 2200 are not leap years, but 1600, 2000, and 2400 are leap years.
ISLEAP output is 1 if the year is a leap year otherwise is 0.
The input is an year (an Integer value) or an array: by default, if invoked without argument, ISLEAP uses the current year. ISLEAP is valid only for the Gregorian calendar so, if you input and Year<=1582 ISLEAP returns an error.
If you use t=isleap(2007) the answer will be t = 0; if you use t=isleap([2007 2008]) the answer will be t = 0 1.
As I wrote, the main aim was the use of logical operators:
1 2 3 | A=mod(Year,4); %If Year is divisible by 4 MOD output is 0 B=mod(Year,100); %If Year is divisible by 100 MOD output is 0 C=mod(Year,400); %If Year is divisible by 400 MOD output is 0 |
Now all A and C value must be inverted by the NOT (~) operator because a leap year is divisible by 4 or by 400.
Finally a leap year must be divisible by 400 (~C) OR (|) it is divisible by 4 (~A) AND (&) it is not a multiple of 100 (B)
4 | x = ~A & (B | ~C) |
If any problems occurs in execution, or if you found a bug, have a suggestion or question just contact me at:
giuseppe dot cardillo-edta at poste dot it
You can visit my homepage http://home.tele2.it/cardillo
My profile on XING http://www.xing.com/go/invita/13675097
My profile on LinkedIN http://it.linkedin.com/in/giuseppecardillo
Download Now
Popularity: 1% [?]
Related Posts
Comments
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>

















































