Linked-List: constructor NewLinkedListA() accepts any type of int and float
This commit is contained in:
@@ -65,6 +65,38 @@ func AnyInteger(v any) (i int64, ok bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func FixAnyNumber(v any) (fixed any) {
|
||||
switch unboxed := v.(type) {
|
||||
case int:
|
||||
fixed = int64(unboxed)
|
||||
case int8:
|
||||
fixed = int64(unboxed)
|
||||
case int16:
|
||||
fixed = int64(unboxed)
|
||||
case int32:
|
||||
fixed = int64(unboxed)
|
||||
case uint:
|
||||
fixed = int64(unboxed)
|
||||
case uint8:
|
||||
fixed = int64(unboxed)
|
||||
case uint16:
|
||||
fixed = int64(unboxed)
|
||||
case uint32:
|
||||
fixed = int64(unboxed)
|
||||
case uint64:
|
||||
if unboxed <= MaxUint64Allowed {
|
||||
fixed = int64(unboxed)
|
||||
} else {
|
||||
fixed = float64(unboxed)
|
||||
}
|
||||
case float32:
|
||||
fixed = float64(unboxed)
|
||||
default:
|
||||
fixed = v
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func ToGoInt(value any, description string) (i int, err error) {
|
||||
if valueInt64, ok := value.(int64); ok {
|
||||
i = int(valueInt64)
|
||||
|
||||
Reference in New Issue
Block a user