// NumberToInt convert interface{} to int64
975014
func NumberToInt(number interface{}) (int64, error) {
	switch v := number.(type) {
	case int32:
		return int64(v), nil
	case int64:
		return v, nil
	case float32:
		return int64(v), nil
	case float64:
		return int64(v), nil
	}
	result, err := strconv.ParseInt(fmt.Sprintf("%v", number), 10, 64)
	if err != nil {
		return 0, err
	}
	return result, nil
}
377542
func (t Result) Int() int64 {
	switch t.Type {
	default:
		return 0
	case True:
		return 1
	case String:
		n, _ := parseInt(t.Str)
		return n
	case Number:
		// try to directly convert the float64 to int64
		n, ok := floatToInt(t.Num)
		if !ok {
			// now try to parse the raw string
			n, ok = parseInt(t.Raw)
			if !ok {
				// fallback to a standard conversion
				return int64(t.Num)
			}
		}
		return n
	}
}
925046
func ToInt64(val interface{}) (int64, error) {
	switch v := val.(type) {
	case int:
		return int64(v), nil
	case int8:
		return int64(v), nil
	case int16:
		return int64(v), nil
	case int32:
		return int64(v), nil
	case int64:
		return v, nil
	case float32:
		f := val.(float32)
		i := int64(f)

		if f != float32(i) {
			return 0, errors.Errorf("invalid casting float32 (%f) to int64, precision loss detected", f)
		}
		return i, nil
	case float64:
		f := val.(float64)
		i := int64(f)

		if f != float64(i) {
			return 0, errors.Errorf("invalid casting float64 (%f) to int64, precision loss detected", f)
		}
		return i, nil
	case string:
		return strconv.ParseInt(v, 10, 64)
	case json.Number:
		return v.Int64()
	default:
		return 0, fmt.Errorf("Unhandled type: %t", v)
	}
}
831481
func Int(input interface{}) (output int64, err error) {

	switch castValue := input.(type) {
	case Inter:
		output = castValue.Int()
		return
	case string:
		output, err = strconv.ParseInt(castValue, 10, 64)
		return
	case []byte:
		output, err = strconv.ParseInt(string(castValue), 10, 64)
		return
	case int:
		output = int64(castValue)
		return
	case int8:
		output = int64(castValue)
		return
	case int16:
		output = int64(castValue)
		return
	case int32:
		output = int64(castValue)
		return
	case int64:
		output = int64(castValue)
		return
	case uint:
		output = int64(castValue)
		return
	case uint8:
		output = int64(castValue)
		return
	case uint16:
		output = int64(castValue)
		return
	case uint32:
		output = int64(castValue)
		return
	case uint64:
		output = int64(castValue)
		return
	case float32:
		output = int64(castValue)
		return
	case float64:
		output = int64(castValue)
		return
	case bool:
		output = int64(0)
		if castValue {
			output = int64(1)
		}
		return
	case nil:
		output = int64(0)
		return
	default:
		err = NewCastError("Could not convert to int")
	}
	return
}
241046
func (v Value) Int() (int, error) {
	i, err := strconv.Atoi(v.String())
	if err != nil {
		return 0, v.invalidTypeError(err, "int")
	}
	return i, nil
}
1270114
func (c *client) Int(key string, fallback int) int {
	if i, err := strconv.Atoi(c.Getenv(key)); err == nil {
		return i
	}

	return fallback
}
911787
func (r *Reader) toInt(input string) int {
	result, err := strconv.Atoi(prune(input))
	if err != nil {
		return -1
	}
	return result
}
693672
func (l *Locking) Int() (v int) {
	l.Lock()
	v = l.R.Int()
	l.Unlock()
	return
}
533563
func ToInt64(v interface{}) int64 {
	if str, ok := v.(string); ok {
		return strToInt64(str)
	}

	val := reflect.Indirect(reflect.ValueOf(v))
	switch val.Kind() {
	case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
		return val.Int()
	case reflect.Uint8, reflect.Uint16, reflect.Uint32:
		return int64(val.Uint())
	case reflect.Uint, reflect.Uint64:
		tv := val.Uint()
		// this can overflow and give -1, but IMO this is better than
		// returning maxint64
		return int64(tv)
	case reflect.Float32, reflect.Float64:
		return int64(val.Float())
	case reflect.Bool:
		if val.Bool() {
			return 1
		}
		return 0
	default:
		return 0
	}
}
757402
func (c *Cell) Int() (int, error) {
	f, err := strconv.ParseFloat(c.Value, 64)
	if err != nil {
		return -1, err
	}
	return int(f), nil
}
1229620
func IntToNumber(i *big.Int) ast.Number {
	return ast.Number(i.String())
}
4534
func (m *MT19937) Int() int {
	u := uint(m.Int32())
	return int(u << 1 >> 1)
}
489880
func toInt32(value Value) int32 {
	{
		switch value := value.value.(type) {
		case int8:
			return int32(value)
		case int16:
			return int32(value)
		case int32:
			return value
		}
	}
	floatValue := value.float64()
	if math.IsNaN(floatValue) || math.IsInf(floatValue, 0) {
		return 0
	}
	if floatValue == 0 { // This will work for +0 & -0
		return 0
	}
	remainder := math.Mod(floatValue, float_2_32)
	if remainder > 0 {
		remainder = math.Floor(remainder)
	} else {
		remainder = math.Ceil(remainder) + float_2_32
	}
	if remainder > float_2_31 {
		return int32(remainder - float_2_32)
	}
	return int32(remainder)
}
112036
func ConvertIntToInt(val int64, lowerBound int64, upperBound int64, tp byte) (int64, error) {
	if val < lowerBound {
		return lowerBound, overflow(val, tp)
	}

	if val > upperBound {
		return upperBound, overflow(val, tp)
	}

	return val, nil
}
293641
func Int() gopter.Gen {
	return Int64Range(math.MinInt32, math.MaxInt32).
		Map(int64ToInt).
		WithShrinker(IntShrinker)
}
16982
func ToInt(str string) (int64, error) {
	res, err := strconv.ParseInt(str, 0, 64)
	if err != nil {
		res = 0
	}
	return res, err
}
644339
func tryToInt(v reflect.Value) (int, error) {
	if v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface {
		v = v.Elem()
	}
	switch v.Kind() {
	case reflect.Float64, reflect.Float32:
		return int(v.Float()), nil
	case reflect.Int64, reflect.Int32, reflect.Int16, reflect.Int8, reflect.Int:
		return int(v.Int()), nil
	case reflect.Bool:
		if v.Bool() {
			return 1, nil
		}
		return 0, nil
	case reflect.String:
		s := v.String()
		var i int64
		var err error
		if strings.HasPrefix(s, "0x") {
			i, err = strconv.ParseInt(s, 16, 64)
		} else {
			i, err = strconv.ParseInt(s, 10, 64)
		}
		if err == nil {
			return int(i), nil
		}
	}
	return 0, errors.New("couldn't convert to integer")
}