import math


def gregorian_to_jd(y, m, d):
	"""Return Julian Day of a Gregorian or Julian date

	Negative Julian Day (i.e. y < -4712 or 4713 BC) is not supported.
	
	Param:
	y as int - year
	m as int - month [1..12]
	d as int - day [1..31]
	"""
	if y < -4712: raise ValueError('year < -4712 is not supported')

	if m <= 2:
		m += 12; y -= 1
	if y > 1582 or (y == 1582 and (m > 10 or (m == 10 and d >= 15))):
		# first gregorian is 15-oct-1582
		a = math.floor(y / 100.0)
		b = 2 + math.floor(a / 4.0) - a
	else: # invalid dates (5-14) are also considered as julian
		b = 0
	abs_jd = (1720994.5 + math.floor(365.25 * y) + math.floor(30.6001 * (m + 1))
		+ d + b)
	return abs_jd