Tag Archives: Math

365.2425 Days in a Year?

I was looking through some of the posts on Google+ and noticed that one of Douglas Crockford’s posts alluded to the fact that there are 365.2425 days on average in a year. At first I thought that the number should’ve actually been 365.25 due to us seeing a leap year every 4 years, but then I remembered that leap years don’t always happen every 4 years.

The rule is that a leap year will be a year evenly divisible by 4 and if it is evenly divisible 100 it must also be evenly divisible by 400. Therefore 1896 was a leap year, but the next leap year wasn’t observed until 1904.

Keeping all of this in mind, let’s see if we come to the same conclusion that there are 365.2425 days in a year on average. First, let’s determine how many days are in the typical 4 year period:
365 days × 4 + 1 leap day = 1,461 days

Now let’s determine how many days there actually are in a 400 year time span. Since we already have a rough calculation for 4 years, we can multiply that by 100 and then account for the 3 times the 3 leap days that wouldn’t occur because even though the year would be divisible by 4 and 100 it wouldn’t be divisible by 400:
1,461 days × 100 - 3 leap days = 146,097 days

Now let’s simply divide the number of days in a 400 year time span by 400 to get the average amount of days in a year:
146,097 ÷ 400 = 365.2425

So now you know why it is said that on average a year is 365.2425 days long. :cool:

JavaScript Snippet – Using Degrees with Cosine, Sine & Tangent

Now Available in YourJS

Yesterday I was working with Math.cos, Math.sin and Math.tan and was thinking it would be nice to have the equivalent functions which accept the values in degrees instead of radians. For that reason I wrote the following definitions for Math.cosd, Math.sind and Math.tand:

After executing the above 5 lines you will be able to get the cosine at 45° by doing Math.cosd(45) or the sine at 75° by doing Math.sind(75) or the tangent at 135° by doing Math.tand(135). WARNING: this does extend a built-in object. If you would like these functions in a separate Degrees object so as to avoid mutating a built-in object you could use this:

(function (R) {
  Degrees = {
    cosd: function(d) { return Math.cos(d * R); },
    sind: function(d) { return Math.sin(d * R); },
    tand: function(d) { return Math.tan(d * R); }
})(Math.PI / 180);

Have fun! :cool: