Skip to content

Commit

Permalink
Example #13: no approximation
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Jun 13, 2022
1 parent 434602b commit b195e1f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lesson8/13_add_type_parameters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Again - no automatic type conversion is performed!

package main

import "fmt"

type numeric interface {
int | float64 | complex128
}

func add[T numeric](x T, y T) T {
return x + y
}

type myInt int

type myFloat float64

type myComplex complex128

func main() {
var x myInt = 42
var y myFloat = 3.14
var z myComplex = 1 + 2i

fmt.Println(add(x, x))
fmt.Println(add(y, y))
fmt.Println(add(z, z))
}

0 comments on commit b195e1f

Please sign in to comment.