// calcDaynr calculates days since 0000-00-00.
325022
func calcDaynr(year, month, day int) int {
	if year == 0 && month == 0 {
		return 0
	}

	delsum := 365*year + 31*(month-1) + day
	if month <= 2 {
		year--
	} else {
		delsum -= (month*4 + 23) / 10
	}
	temp := ((year/100 + 1) * 3) / 4
	return delsum + year/4 - temp
}
1287678
func LinearDelayFunction(retryDelay uint, retries uint) time.Duration {
	return time.Duration(retryDelay*retries) * time.Millisecond
}
1198010
func retryDelay(count int) float64 {
	return math.Pow(float64(count), 4) + 15 + float64(rand.Intn(30)*(count+1))
}
1193562
func (f *FreqDist) rToNr(bins int) map[int]int {
	tmpRToNr := map[int]int{}

	for _, value := range f.Samples {
		tmpRToNr[value] += 1
	}

	if bins == 0 {
		tmpRToNr[0] = 0
	} else {
		tmpRToNr[0] = bins - f.B()
	}

	return tmpRToNr
}
433499
func (term Range) Days() int {
	// Set timezones both to UTC to avoid issues of daylight savings
	if term.Start.IsZero() || term.End.IsZero() {
		return 0
	}
	// A single day range includes itself
	return int(term.End.UTC().Sub(term.Start.UTC()).Hours()/24) + 1
}
652972
func (c *StandardCounter) Dec(i int64) {
	atomic.AddInt64(&c.count, -i)
}
268738
func (ci *CarbonInterval) DiffInHours() int64 {
	return ci.End.DiffInHours(ci.Start, true)
}
538888
func AdxR(inHigh []float64, inLow []float64, inClose []float64, inTimePeriod int) []float64 {

	outReal := make([]float64, len(inClose))
	startIdx := (2 * inTimePeriod) - 1
	tmpadx := Adx(inHigh, inLow, inClose, inTimePeriod)
	i := startIdx
	j := startIdx + inTimePeriod - 1
	for outIdx := startIdx + inTimePeriod - 1; outIdx < len(inClose); outIdx, i, j = outIdx+1, i+1, j+1 {
		outReal[outIdx] = ((tmpadx[i] + tmpadx[j]) / 2.0)
	}
	return outReal
}
295312
func (c Calendar) formatDateTimeComponentDayOfWeek(datetime time.Time, length int) (string, error) {
	switch length {
	case datetimeFormatLength1Plus:
		return c.formatDateTimeComponentDayOfWeekWide(datetime.Weekday()), nil
	case datetimeFormatLength2Plus:
		return c.formatDateTimeComponentDayOfWeekShort(datetime.Weekday()), nil
	case datetimeFormatLengthAbbreviated:
		return c.formatDateTimeComponentDayOfWeekAbbreviated(datetime.Weekday()), nil
	case datetimeFormatLengthWide:
		return c.formatDateTimeComponentDayOfWeekWide(datetime.Weekday()), nil
	case datetimeFormatLengthNarrow:
		return c.formatDateTimeComponentDayOfWeekNarrow(datetime.Weekday()), nil
	}

	return "", fmt.Errorf("unsupported year day-of-week: %d", length)
}
519437
func JulianDayNumber(t time.Time) int {
	// algorithm from http://www.tondering.dk/claus/cal/julperiod.php#formula
	utc := t.UTC()
	a := (14 - int(utc.Month())) / 12
	y := utc.Year() + 4800 - a
	m := int(utc.Month()) + 12*a - 3

	jdn := utc.Day() + (153*m+2)/5 + 365*y + y/4 - y/100 + y/400 - 32045
	if utc.Hour() < 12 {
		jdn--
	}
	return jdn
}
1244382
func calculateOcenaniaBoxingDay(year int, loc *time.Location) (time.Month, int) {
	d := time.Date(year, time.December, 26, 0, 0, 0, 0, loc)
	wd := d.Weekday()
	if wd == 0 || wd == 6 {
		d = d.AddDate(0, 0, 2)
	}

	return d.Month(), d.Day()
}
87706
func (c Calendar) formatDateTimeComponentYear(datetime time.Time, length int) (string, error) {
	year := datetime.Year()
	switch length {
	case datetimeFormatLength1Plus:
		return c.formatDateTimeComponentYearLengthWide(year), nil
	case datetimeFormatLength2Plus:
		return c.formatDateTimeComponentYearLength2Plus(year), nil
	case datetimeFormatLengthWide:
		return c.formatDateTimeComponentYearLengthWide(year), nil
	}

	return "", fmt.Errorf("unsupported year length: %d", length)
}
398874
func calcJulianCentury(julianDay []float64) (julianCentury []float64) {
	for index := 0; index < len(julianDay); index++ {
		temp := (julianDay[index] - 2451545.0) / 36525.0
		julianCentury = append(julianCentury, temp)
	}
	return
}
887480
func (d *calcHeightData) calcHeight(node *treeNode) {
	d.currentHeight++

	if node.left != nil {
		d.calcHeight(node.left)
	}

	if node.right != nil {
		d.calcHeight(node.right)
	}

	if d.currentHeight > d.maxHeight {
		d.maxHeight = d.currentHeight
	}
	d.currentHeight--
}
578142
func Dur(max time.Duration) time.Duration {
	return time.Duration(Int63n(int64(max)))
}
130730
func (fr *fr_CA) WeekdayNarrow(weekday time.Weekday) string {
	return fr.daysNarrow[weekday]
}
235133
func calcDistance(p1 *pb.Point, p2 *pb.Point) int32 {
	const CordFactor float64 = 1e7
	const R = float64(6371000) // earth radius in metres
	lat1 := toRadians(float64(p1.Latitude) / CordFactor)
	lat2 := toRadians(float64(p2.Latitude) / CordFactor)
	lng1 := toRadians(float64(p1.Longitude) / CordFactor)
	lng2 := toRadians(float64(p2.Longitude) / CordFactor)
	dlat := lat2 - lat1
	dlng := lng2 - lng1

	a := math.Sin(dlat/2)*math.Sin(dlat/2) +
		math.Cos(lat1)*math.Cos(lat2)*
			math.Sin(dlng/2)*math.Sin(dlng/2)
	c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))

	distance := R * c
	return int32(distance)
}