// getnum parses s[0:1] or s[0:2] (fixed forces the latter)
// as a decimal integer and returns the integer and the
// remainder of the string.
963600
func getnum(s string, fixed bool) (int, string, error) {
	if !isDigit(s, 0) {
		return 0, s, errBad
	}
	if !isDigit(s, 1) {
		if fixed {
			return 0, s, errBad
		}
		return int(s[0] - '0'), s[1:], nil
	}
	return int(s[0]-'0')*10 + int(s[1]-'0'), s[2:], nil
}
816885
func ParseNumber(numStr string) *Number {
	n := &Number{}

	numStr = strings.TrimSpace(numStr)
	n.Value, _ = new(big.Rat).SetString(numStr)
	i := strings.Index(numStr, ".")
	if i != -1 {
		n.Precision = len(numStr) - i - 1
	} else {
		n.Precision = 0
	}

	return n
}
1357527
func (i Int8) Get() (int8, error) {
	if !i.Present() {
		var zero int8
		return zero, errors.New("value not present")
	}
	return *i.value, nil
}
553722
func getInt(unk interface{}) int64 {
	switch i := unk.(type) {
	case int64:
		return i
	case float64:
		return int64(i)
	case string:
		v, err := strconv.ParseInt(i, 10, 64)
		if err != nil {
			return int64(0)
		}
		return v
	default:
		return int64(0)
	}
}
868394
func Get(n int) string {
	b := make([]rune, n)
	for i := range b {
		b[i] = Alphabet[rand.Intn(len(Alphabet))]
	}

	return string(b)
}
93448
func (nu *Numbered) Get(id int64, purpose string) (val interface{}, err error) {
	nu.mu.Lock()
	defer nu.mu.Unlock()
	nw, ok := nu.resources[id]
	if !ok {
		return nil, fmt.Errorf("not found")
	}
	if nw.inUse {
		return nil, fmt.Errorf("in use: %s", nw.purpose)
	}
	nw.inUse = true
	nw.purpose = purpose
	return nw.val, nil
}
943144
func (nu *Numbered) Get(id int64, purpose string) (val interface{}, err error) {
	nu.mu.Lock()
	defer nu.mu.Unlock()
	nw, ok := nu.resources[id]
	if !ok {
		if val, ok := nu.recentlyUnregistered.Get(fmt.Sprintf("%v", id)); ok {
			unreg := val.(*unregistered)
			return nil, fmt.Errorf("ended at %v (%v)", unreg.timeUnregistered.Format("2006-01-02 15:04:05.000 MST"), unreg.reason)
		}
		return nil, fmt.Errorf("not found")
	}
	if nw.inUse {
		return nil, fmt.Errorf("in use: %s", nw.purpose)
	}
	nw.inUse = true
	nw.purpose = purpose
	return nw.val, nil
}
1263428
func (value Value) number() (number _number) {
	switch value := value.value.(type) {
	case int8:
		number.int64 = int64(value)
		return
	case int16:
		number.int64 = int64(value)
		return
	case uint8:
		number.int64 = int64(value)
		return
	case uint16:
		number.int64 = int64(value)
		return
	case uint32:
		number.int64 = int64(value)
		return
	case int:
		number.int64 = int64(value)
		return
	case int64:
		number.int64 = value
		return
	}

	float := value.float64()
	if float == 0 {
		return
	}

	number.kind = numberFloat
	number.float64 = float

	if math.IsNaN(float) {
		number.kind = numberNaN
		return
	}

	if math.IsInf(float, 0) {
		number.kind = numberInfinity
	}

	if float >= float_maxInt64 {
		number.int64 = math.MaxInt64
		return
	}

	if float <= float_minInt64 {
		number.int64 = math.MinInt64
		return
	}

	integer := float64(0)
	if float > 0 {
		integer = math.Floor(float)
	} else {
		integer = math.Ceil(float)
	}

	if float == integer {
		number.kind = numberInteger
	}
	number.int64 = int64(float)
	return
}
1304963
func (p *PullRequest) GetNumber() int {
	if p == nil || p.Number == nil {
		return 0
	}
	return *p.Number
}
925826
func (p *packetNumberGenerator) getRandomNumber() uint16 {
	b := make([]byte, 2)
	rand.Read(b) // ignore the error here

	num := uint16(b[0])<<8 + uint16(b[1])
	return num
}
918594
func ExtractTimeNum(unit string, t Time) (int64, error) {
	switch strings.ToUpper(unit) {
	case "MICROSECOND":
		return int64(t.Time.Microsecond()), nil
	case "SECOND":
		return int64(t.Time.Second()), nil
	case "MINUTE":
		return int64(t.Time.Minute()), nil
	case "HOUR":
		return int64(t.Time.Hour()), nil
	case "DAY":
		return int64(t.Time.Day()), nil
	case "WEEK":
		week := t.Time.Week(0)
		return int64(week), nil
	case "MONTH":
		// TODO: Consider time_zone variable.
		t1, err := t.Time.GoTime(gotime.Local)
		if err != nil {
			return 0, errors.Trace(err)
		}
		return int64(t1.Month()), nil
	case "QUARTER":
		m := int64(t.Time.Month())
		// 1 - 3 -> 1
		// 4 - 6 -> 2
		// 7 - 9 -> 3
		// 10 - 12 -> 4
		return (m + 2) / 3, nil
	case "YEAR":
		return int64(t.Time.Year()), nil
	case "SECOND_MICROSECOND":
		return int64(t.Time.Second())*1000000 + int64(t.Time.Microsecond()), nil
	case "MINUTE_MICROSECOND":
		_, m, s := t.Clock()
		return int64(m)*100000000 + int64(s)*1000000 + int64(t.Time.Microsecond()), nil
	case "MINUTE_SECOND":
		_, m, s := t.Clock()
		return int64(m*100 + s), nil
	case "HOUR_MICROSECOND":
		h, m, s := t.Clock()
		return int64(h)*10000000000 + int64(m)*100000000 + int64(s)*1000000 + int64(t.Time.Microsecond()), nil
	case "HOUR_SECOND":
		h, m, s := t.Clock()
		return int64(h)*10000 + int64(m)*100 + int64(s), nil
	case "HOUR_MINUTE":
		h, m, _ := t.Clock()
		return int64(h)*100 + int64(m), nil
	case "DAY_MICROSECOND":
		h, m, s := t.Clock()
		d := t.Time.Day()
		return int64(d*1000000+h*10000+m*100+s)*1000000 + int64(t.Time.Microsecond()), nil
	case "DAY_SECOND":
		h, m, s := t.Clock()
		d := t.Time.Day()
		return int64(d)*1000000 + int64(h)*10000 + int64(m)*100 + int64(s), nil
	case "DAY_MINUTE":
		h, m, _ := t.Clock()
		d := t.Time.Day()
		return int64(d)*10000 + int64(h)*100 + int64(m), nil
	case "DAY_HOUR":
		h, _, _ := t.Clock()
		d := t.Time.Day()
		return int64(d)*100 + int64(h), nil
	case "YEAR_MONTH":
		y, m := t.Time.Year(), t.Time.Month()
		return int64(y)*100 + int64(m), nil
	default:
		return 0, errors.Errorf("invalid unit %s", unit)
	}
}
914294
func (node *NumberLiteral) Number() interface{} {
	if node.IsInt {
		return int(node.Value)
	}

	return node.Value
}
331558
func (d *DiscussionComment) GetNumber() int {
	if d == nil || d.Number == nil {
		return 0
	}
	return *d.Number
}
1075038
func parseTwoNumeric(input string) (int, string) {
	if len(input) > 1 && input[0] == '0' {
		return 0, input[1:]
	}
	matched := twoDigitRegex.FindAllString(input, -1)
	if len(matched) == 0 {
		return 0, input
	}

	str := matched[0]
	v, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		return 0, input
	}
	return int(v), input[len(str):]
}
452138
func (f EventFields) GetInt(key string) int {
	val, found := f[key]
	if !found {
		return 0
	}
	v, ok := val.(int)
	if !ok {
		f, ok := val.(float64)
		if ok {
			v = int(f)
		}
	}
	return v
}
1297740
func (cache *Cache) GetInt(key int64) (value []byte, err error) {
	var bKey [8]byte
	binary.LittleEndian.PutUint64(bKey[:], uint64(key))
	return cache.Get(bKey[:])
}
1346463
func (s *Session) GetInt(key string, def int64) int64 {
	v, ok := s.Values[key]
	if !ok {
		return def
	}

	return v.(int64)
}