0

I am writing a program which converts a Gregorian calender date to a Julian day number. I am having some problems implementing the portion which includes time. For reference - http://en.wikipedia.org/wiki/Julian_day (scroll to calculation section)

My code:

```
jdn_t gregorian_to_jdn_with_time( year_t year, month_t month, day_t day, hour_t hour, min_t min, sec_t sec ) {
assert( month <= 12 && "Max month is December(12)" );
assert( month >= 1 && "Min month is January(1)" );
assert( day >= 1 && "Min day is 1" );
assert( day <= 31 && "Max day is 31" );
// TODO: Implement the conversion from Gregorian to Jdn
// http://en.wikipedia.org/wiki/Julian_day
long long a = ( 14 - month ) / 12;
long long y = year + 4800 + a;
long long m = month + 12 * a - 3;
jdn_t jdn = day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045 - 0.5;
jdn_t jdnTime = jdn + (hour - 12) / 24 + min / 1440 + sec / 86400 ;
return jdnTime;
}
```

Typedefs:

```
typedef double jdn_t;
typedef long long year_t;
typedef int month_t;
typedef int day_t;
typedef int hour_t;
typedef int min_t;
typedef int sec_t;
```

The jdnTime turns out to be some huge negative number when I try to test it with January 1, 2000 at 12:00:00 which should equate to julian day # 2451545.0. I have no idea what I'm doing wrong, any suggestions?