func int64ToUint64Checked(v int64) (uint64, error) {
	if v < 0 {
		return 0, errUintOverflow
	}
	return uint64(v), nil
}
int64toUint64Checked converts an int64 to a uint64 value.

If the conversion fails due to overflow the error return value will be non-nil.
package types
import (
	"math"
	"time"
)
var (
	doubleTwoTo64 = math.Ldexp(1.0, 64)
)
func addInt64Checked(x, y int64) (int64, error) {
	if (y > 0 && x > math.MaxInt64-y) || (y < 0 && x < math.MinInt64-y) {
		return 0, errIntOverflow
	}
	return x + y, nil
}
func subtractInt64Checked(x, y int64) (int64, error) {
	if (y < 0 && x > math.MaxInt64+y) || (y > 0 && x < math.MinInt64+y) {
		return 0, errIntOverflow
	}
	return x - y, nil
}
func negateInt64Checked(x int64) (int64, error) {
	if x == math.MinInt64 {
		return 0, errIntOverflow
	}
	return -x, nil
}
func multiplyInt64Checked(x, y int64) (int64, error) {
	if (x == -1 && y == math.MinInt64) || (y == -1 && x == math.MinInt64) ||
		(x > 0 && y > 0 && x > math.MaxInt64/y) ||
		(x > 0 && y < 0 && y < math.MinInt64/x) ||
		(x < 0 && y > 0 && x < math.MinInt64/y) ||
		(x < 0 && y < 0 && y < math.MaxInt64/x) {
		return 0, errIntOverflow
	}
	return x * y, nil
}
func divideInt64Checked(x, y int64) (int64, error) {
	if y == 0 {
		return 0, errDivideByZero
	}
	if x == math.MinInt64 && y == -1 {
		return 0, errIntOverflow
	}
	return x / y, nil
}
func moduloInt64Checked(x, y int64) (int64, error) {
	if y == 0 {
		return 0, errModulusByZero
	}
	if x == math.MinInt64 && y == -1 {
		return 0, errIntOverflow
	}
	return x % y, nil
}
func addUint64Checked(x, y uint64) (uint64, error) {
	if y > 0 && x > math.MaxUint64-y {
		return 0, errUintOverflow
	}
	return x + y, nil
}
func subtractUint64Checked(x, y uint64) (uint64, error) {
	if y > x {
		return 0, errUintOverflow
	}
	return x - y, nil
}
func multiplyUint64Checked(x, y uint64) (uint64, error) {
	if y != 0 && x > math.MaxUint64/y {
		return 0, errUintOverflow
	}
	return x * y, nil
}
func divideUint64Checked(x, y uint64) (uint64, error) {
	if y == 0 {
		return 0, errDivideByZero
	}
	return x / y, nil
}
func moduloUint64Checked(x, y uint64) (uint64, error) {
	if y == 0 {
		return 0, errModulusByZero
	}
	return x % y, nil
}
func addDurationChecked(x, y time.Duration) (time.Duration, error) {
	val, err := addInt64Checked(int64(x), int64(y))
	if err != nil {
		return time.Duration(0), err
	}
	return time.Duration(val), nil
}
func subtractDurationChecked(x, y time.Duration) (time.Duration, error) {
	val, err := subtractInt64Checked(int64(x), int64(y))
	if err != nil {
		return time.Duration(0), err
	}
	return time.Duration(val), nil
}
func negateDurationChecked(x time.Duration) (time.Duration, error) {
	val, err := negateInt64Checked(int64(x))
	if err != nil {
		return time.Duration(0), err
	}
	return time.Duration(val), nil
}
func addTimeDurationChecked(x time.Time, y time.Duration) (time.Time, error) {
	sec1 := x.Truncate(time.Second).Unix()                 
	nsec1 := x.Sub(x.Truncate(time.Second)).Nanoseconds()  
	sec2 := int64(y) / int64(time.Second)   
	nsec2 := int64(y) % int64(time.Second)  
	sec, err := addInt64Checked(sec1, sec2)
	if err != nil {
		return time.Time{}, err
	}
	nsec := nsec1 + nsec2
	if nsec < 0 || nsec >= int64(time.Second) {
		sec, err = addInt64Checked(sec, nsec/int64(time.Second))
		if err != nil {
			return time.Time{}, err
		}
		nsec -= (nsec / int64(time.Second)) * int64(time.Second)
		if nsec < 0 {
			sec, err = addInt64Checked(sec, -1)
			if err != nil {
				return time.Time{}, err
			}
			nsec += int64(time.Second)
		}
	}
	if sec < minUnixTime || sec > maxUnixTime {
		return time.Time{}, errTimestampOverflow
	}
	return time.Unix(sec, nsec).In(x.Location()), nil
}
func subtractTimeChecked(x, y time.Time) (time.Duration, error) {
	sec1 := x.Truncate(time.Second).Unix()                 
	nsec1 := x.Sub(x.Truncate(time.Second)).Nanoseconds()  
	sec2 := y.Truncate(time.Second).Unix()                 
	nsec2 := y.Sub(y.Truncate(time.Second)).Nanoseconds()  
	sec, err := subtractInt64Checked(sec1, sec2)
	if err != nil {
		return time.Duration(0), err
	}
	nsec := nsec1 - nsec2
	tsec, err := multiplyInt64Checked(sec, int64(time.Second))
	if err != nil {
		return time.Duration(0), err
	}
	val, err := addInt64Checked(tsec, nsec)
	if err != nil {
		return time.Duration(0), err
	}
	return time.Duration(val), nil
}
func subtractTimeDurationChecked(x time.Time, y time.Duration) (time.Time, error) {
	val, err := negateDurationChecked(y)
	if err != nil {
		return time.Time{}, err
	}
	return addTimeDurationChecked(x, val)
}
func doubleToInt64Checked(v float64) (int64, error) {
	if math.IsInf(v, 0) || math.IsNaN(v) || v <= float64(math.MinInt64) || v >= float64(math.MaxInt64) {
		return 0, errIntOverflow
	}
	return int64(v), nil
}
func doubleToUint64Checked(v float64) (uint64, error) {
	if math.IsInf(v, 0) || math.IsNaN(v) || v < 0 || v >= doubleTwoTo64 {
		return 0, errUintOverflow
	}
	return uint64(v), nil
}