1
2
3
4
5
6 package simdfmt
7
8 import "internal/strconv"
9
10
11 type Number interface {
12 int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | float32 | float64
13 }
14
15
16 func SliceToString[T Number](x []T) string {
17 var s []byte
18 s = append(s, '{')
19 for i, y := range x {
20 if i > 0 {
21 s = append(s, ',')
22 }
23 switch e := any(y).(type) {
24 case int8:
25 s = strconv.AppendInt(s, int64(e), 10)
26 case int16:
27 s = strconv.AppendInt(s, int64(e), 10)
28 case int32:
29 s = strconv.AppendInt(s, int64(e), 10)
30 case int64:
31 s = strconv.AppendInt(s, e, 10)
32 case uint8:
33 s = strconv.AppendUint(s, uint64(e), 10)
34 case uint16:
35 s = strconv.AppendUint(s, uint64(e), 10)
36 case uint32:
37 s = strconv.AppendUint(s, uint64(e), 10)
38 case uint64:
39 s = strconv.AppendUint(s, e, 10)
40 case float32:
41 s = strconv.AppendFloat(s, float64(e), 'g', -1, 32)
42 case float64:
43 s = strconv.AppendFloat(s, e, 'g', -1, 64)
44 }
45 }
46 s = append(s, '}')
47 return string(s)
48 }
49
View as plain text