From a8a5d6aaa6f8847e5f93b464f026aa77f411ca50 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Mon, 18 May 2026 06:24:59 +0200 Subject: [PATCH] Linked-List: constructor NewLinkedListA() accepts any type of int and float --- kern/number.go | 32 ++++++++++++++++++++++++++++++++ t_list_test.go | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/kern/number.go b/kern/number.go index bf1b85c..30ba440 100644 --- a/kern/number.go +++ b/kern/number.go @@ -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) diff --git a/t_list_test.go b/t_list_test.go index ef8a822..6abbe2f 100644 --- a/t_list_test.go +++ b/t_list_test.go @@ -70,7 +70,7 @@ func TestLinkedListParser(t *testing.T) { section := "Linked-List" inputs := []inputType{ - /* 1 */ {`[<1,2>]`, kern.NewLinkedListA(int64(1), int64(2)), nil}, + /* 1 */ {`[<1,2>]`, kern.NewLinkedListA(1, 2), nil}, } // t.Setenv("EXPR_PATH", ".")