<commit_before>package generic

import (
	"math"
	"strconv"
	"time"
)

func asBool(x interface{}) (result bool, isValid ValidFlag, err error) {
	switch x.(type) {
	case nil:
		return result, false, nil
	case int:
		result = x.(int) != 0
	case int8:
		result = x.(int8) != 0
	case int16:
		result = x.(int16) != 0
	case int32:
		result = x.(int32) != 0
	case int64:
		result = x.(int64) != 0
	case uint:
		result = x.(uint) != 0
	case uint8:
		result = x.(uint8) != 0
	case uint16:
		result = x.(uint16) != 0
	case uint32:
		result = x.(uint32) != 0
	case uint64:
		result = x.(uint64) != 0
	case float32:
		result = x.(float32) != 0
	case float64:
		result = x.(float64) != 0
	case bool:
		result = x.(bool)
	case string:
		b, err := strconv.ParseBool(x.(string))
		if err != nil {
			return result, false, ErrInvalidGenericValue{Value: x}
		}
		result = b
	default:
		return result, false, ErrInvalidGenericValue{Value: x}
	}
	return result, true, nil
}

func asFloat(x interface{}) (result float64, isValid ValidFlag, err error) {
	switch x.(type) {
	case nil:
		return result, false, nil
	case int:
		result = float64(x.(int))
	case int8:
		result = float64(x.(int8))
	case int16:
		result = float64(x.(int16))
	case int32:
		result = float64(x.(int32))
	case int64:
		result = float64(x.(int64))
	case uint:
		result = float64(x.(uint))
	case uint8:
		result = float64(x.(uint8))
	case uint16:
		result = float64(x.(uint16))
	case uint32:
		result = float64(x.(uint32))
	case uint64:
		result = float64(x.(uint64))
	case float32:
		result = float64(x.(float32))
	case float64:
		result = x.(float64)
	case bool:
		b := x.(bool)
		if b {
			result = 1
		} else {
			result = 0
		}
	case string:
		f, err := strconv.ParseFloat(x.(string), 64)
		if err != nil {
			return result, false, ErrInvalidGenericValue{Value: x}
		}
		result = f
	default:
		return result, false, ErrInvalidGenericValue{Value: x}
	}
	return result, true, nil
}

func asInt(x interface{}) (result int64, isValid ValidFlag, err error) {
	switch x.(type) {
	case nil:
		return result, false, nil
	case int:
		result = int64(x.(int))
	case int8:
		result = int64(x.(int8))
	case int16:
		result = int64(x.(int16))
	case int32:
		result = int64(x.(int32))
	case int64:
		result = x.(int64)
	case uint:
		result = int64(x.(uint))
	case uint8:
		result = int64(x.(uint8))
	case uint16:
		result = int64(x.(uint16))
	case uint32:
		result = int64(x.(uint32))
	case uint64:
		result = int64(x.(uint64))
	case float32:
		result = int64(x.(float32))
	case float64:
		result = int64(x.(float64))
	case bool:
		b := x.(bool)
		if b == true {
			result = 1
		} else {
			result = 0
		}
	case string:
		result, err = strconv.ParseInt(x.(string), 10, 64)
		if err != nil {
			return 0, false, ErrInvalidGenericValue{Value: x}
		}
	default:
		return result, false, ErrInvalidGenericValue{Value: x}
	}
	return result, true, nil
}

func asString(x interface{}) (result string, isValid ValidFlag, err error) {
	switch x.(type) {
	case nil:
		return result, false, nil
	case int:
		result = strconv.FormatInt(int64(x.(int)), 10)
	case int8:
		result = strconv.FormatInt(int64(x.(int8)), 10)
	case int16:
		result = strconv.FormatInt(int64(x.(int16)), 10)
	case int32:
		result = strconv.FormatInt(int64(x.(int32)), 10)
	case int64:
		result = strconv.FormatInt(x.(int64), 10)
	case uint:
		result = strconv.FormatUint(uint64(x.(uint)), 10)
	case uint8:
		result = strconv.FormatUint(uint64(x.(uint8)), 10)
	case uint16:
		result = strconv.FormatUint(uint64(x.(uint16)), 10)
	case uint32:
		result = strconv.FormatUint(uint64(x.(uint32)), 10)
	case uint64:
		result = strconv.FormatUint(x.(uint64), 10)
	case float32:
		f := float64(x.(float32))
		fa := math.Abs(f)
		if math.Ceil(fa) > fa {
			result = strconv.FormatFloat(f, 'f', 10, 64)
		} else {
			result = strconv.FormatInt(int64(x.(float32)), 10)
		}
	case float64:
		f := x.(float64)
		fa := math.Abs(f)
		if math.Ceil(fa) > fa {
			result = strconv.FormatFloat(f, 'f', 10, 64)
		} else {
			result = strconv.FormatInt(int64(x.(float64)), 10)
		}
	case bool:
		result = strconv.FormatBool(x.(bool))
	case string:<commit_msg>fix convert float64 and float32 to string<commit_after>package generic

import (
	"strconv"
	"strings"
	"time"
)

func asBool(x interface{}) (result bool, isValid ValidFlag, err error) {
	switch x.(type) {
	case nil:
		return result, false, nil
	case int:
		result = x.(int) != 0
	case int8:
		result = x.(int8) != 0
	case int16:
		result = x.(int16) != 0
	case int32:
		result = x.(int32) != 0
	case int64:
		result = x.(int64) != 0
	case uint:
		result = x.(uint) != 0
	case uint8:
		result = x.(uint8) != 0
	case uint16:
		result = x.(uint16) != 0
	case uint32:
		result = x.(uint32) != 0
	case uint64:
		result = x.(uint64) != 0
	case float32:
		result = x.(float32) != 0
	case float64:
		result = x.(float64) != 0
	case bool:
		result = x.(bool)
	case string:
		b, err := strconv.ParseBool(x.(string))
		if err != nil {
			return result, false, ErrInvalidGenericValue{Value: x}
		}
		result = b
	default:
		return result, false, ErrInvalidGenericValue{Value: x}
	}
	return result, true, nil
}

func asFloat(x interface{}) (result float64, isValid ValidFlag, err error) {
	switch x.(type) {
	case nil:
		return result, false, nil
	case int:
		result = float64(x.(int))
	case int8:
		result = float64(x.(int8))
	case int16:
		result = float64(x.(int16))
	case int32:
		result = float64(x.(int32))
	case int64:
		result = float64(x.(int64))
	case uint:
		result = float64(x.(uint))
	case uint8:
		result = float64(x.(uint8))
	case uint16:
		result = float64(x.(uint16))
	case uint32:
		result = float64(x.(uint32))
	case uint64:
		result = float64(x.(uint64))
	case float32:
		result = float64(x.(float32))
	case float64:
		result = x.(float64)
	case bool:
		b := x.(bool)
		if b {
			result = 1
		} else {
			result = 0
		}
	case string:
		f, err := strconv.ParseFloat(x.(string), 64)
		if err != nil {
			return result, false, ErrInvalidGenericValue{Value: x}
		}
		result = f
	default:
		return result, false, ErrInvalidGenericValue{Value: x}
	}
	return result, true, nil
}

func asInt(x interface{}) (result int64, isValid ValidFlag, err error) {
	switch x.(type) {
	case nil:
		return result, false, nil
	case int:
		result = int64(x.(int))
	case int8:
		result = int64(x.(int8))
	case int16:
		result = int64(x.(int16))
	case int32:
		result = int64(x.(int32))
	case int64:
		result = x.(int64)
	case uint:
		result = int64(x.(uint))
	case uint8:
		result = int64(x.(uint8))
	case uint16:
		result = int64(x.(uint16))
	case uint32:
		result = int64(x.(uint32))
	case uint64:
		result = int64(x.(uint64))
	case float32:
		result = int64(x.(float32))
	case float64:
		result = int64(x.(float64))
	case bool:
		b := x.(bool)
		if b == true {
			result = 1
		} else {
			result = 0
		}
	case string:
		result, err = strconv.ParseInt(x.(string), 10, 64)
		if err != nil {
			return 0, false, ErrInvalidGenericValue{Value: x}
		}
	default:
		return result, false, ErrInvalidGenericValue{Value: x}
	}
	return result, true, nil
}

func asString(x interface{}) (result string, isValid ValidFlag, err error) {
	switch x.(type) {
	case nil:
		return result, false, nil
	case int:
		result = strconv.FormatInt(int64(x.(int)), 10)
	case int8:
		result = strconv.FormatInt(int64(x.(int8)), 10)
	case int16:
		result = strconv.FormatInt(int64(x.(int16)), 10)
	case int32:
		result = strconv.FormatInt(int64(x.(int32)), 10)
	case int64:
		result = strconv.FormatInt(x.(int64), 10)
	case uint:
		result = strconv.FormatUint(uint64(x.(uint)), 10)
	case uint8:
		result = strconv.FormatUint(uint64(x.(uint8)), 10)
	case uint16:
		result = strconv.FormatUint(uint64(x.(uint16)), 10)
	case uint32:
		result = strconv.FormatUint(uint64(x.(uint32)), 10)
	case uint64:
		result = strconv.FormatUint(x.(uint64), 10)
	case float32:
		fs := strconv.FormatFloat(float64(x.(float32)), 'f', 10, 64)
		result = strings.TrimRight(strings.TrimRight(fs, "0"), ".")
	case float64:
		fs := strconv.FormatFloat(x.(float64), 'f', 10, 64)
		result = strings.TrimRight(strings.TrimRight(fs, "0"), ".")
	case bool:
		result = strconv.FormatBool(x.(bool))
	case string:
{'fraction_non_alphanumeric': 0.1537143556480235, 'fraction_numerical': 0.06608738220536042, 'mean_word_length': 3.598761958356781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '554799', 'n_tokens_mistral': 3675, 'n_tokens_neox': 3164, 'n_words': 839}