aboutsummaryrefslogtreecommitdiffstats
path: root/layout/math.go
diff options
context:
space:
mode:
Diffstat (limited to 'layout/math.go')
-rw-r--r--layout/math.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/layout/math.go b/layout/math.go
new file mode 100644
index 0000000..f09cf00
--- /dev/null
+++ b/layout/math.go
@@ -0,0 +1,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
+}