aboutsummaryrefslogtreecommitdiffstats
path: root/layout/math.go
blob: f09cf00b277cc5557fd08643fa318d2ba2b727e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package layout

type number interface {
	complex | float | integer
}

type complex interface {
	~complex64 | ~complex128
}

type float interface {
	~float32 | ~float64
}

type integer interface {
	signed | unsigned
}

type signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

func sum[N number](ns []N) N {
	var n N
	for i := range ns {
		n += ns[i]
	}
	return n
}