Linked-List: constructor NewLinkedListA() accepts any type of int and float

This commit is contained in:
2026-05-18 06:24:59 +02:00
parent 84b255a51b
commit a8a5d6aaa6
2 changed files with 33 additions and 1 deletions
+32
View File
@@ -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)