包装uint
This commit is contained in:
8
int.go
8
int.go
@ -38,7 +38,7 @@ func (i Int) ToInt8() (int8, error) {
|
||||
// Date : 14:05 2023/5/5
|
||||
func (i Int) ToInt16() (int16, error) {
|
||||
if math.MaxInt16 < int64(i) || math.MinInt16 > int64(i) {
|
||||
return 0, fmt.Errorf("int16 value should between %v and %v ", math.MinInt8, math.MaxInt8)
|
||||
return 0, fmt.Errorf("int16 value should between %v and %v ", math.MinInt16, math.MaxInt16)
|
||||
}
|
||||
return int16(i), nil
|
||||
}
|
||||
@ -50,7 +50,7 @@ func (i Int) ToInt16() (int16, error) {
|
||||
// Date : 14:05 2023/5/5
|
||||
func (i Int) ToInt32() (int32, error) {
|
||||
if math.MaxInt32 < int64(i) || math.MinInt32 > int64(i) {
|
||||
return 0, fmt.Errorf("int32 value should between %v and %v ", math.MinInt8, math.MaxInt8)
|
||||
return 0, fmt.Errorf("int32 value should between %v and %v ", math.MinInt32, math.MaxInt32)
|
||||
}
|
||||
return int32(i), nil
|
||||
}
|
||||
@ -62,7 +62,7 @@ func (i Int) ToInt32() (int32, error) {
|
||||
// Date : 14:06 2023/5/5
|
||||
func (i Int) ToInt64() (int64, error) {
|
||||
if math.MaxInt64 < i || math.MinInt64 > i {
|
||||
return 0, fmt.Errorf("int64 value should between %v and %v ", math.MinInt8, math.MaxInt8)
|
||||
return 0, fmt.Errorf("int64 value should between %v and %v ", math.MinInt64, math.MaxInt64)
|
||||
}
|
||||
return int64(i), nil
|
||||
}
|
||||
@ -74,7 +74,7 @@ func (i Int) ToInt64() (int64, error) {
|
||||
// Date : 14:07 2023/5/5
|
||||
func (i Int) ToInt() (int, error) {
|
||||
if math.MaxInt < i || math.MinInt > i {
|
||||
return 0, fmt.Errorf("int value should between %v and %v ", math.MinInt8, math.MaxInt8)
|
||||
return 0, fmt.Errorf("int value should between %v and %v ", math.MinInt, math.MaxInt)
|
||||
}
|
||||
return int(i), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user