title: How to write a generic function that accepts any numerical type?
body: <p>Coming from JS / TS, I wanted to checkout go and make a simple calculator, since there's the difference between int and float, what is the preferred way to write a functions that takes any number?</p>
  <p>For example:</p>
  <pre><code>package main
  
  func add(a float64, b float64) float64 {
    return a + b;
  }
  
  func main() {
    a := 1;
    b := 2;
    fmt.Println(add(1, 2)); // 3
    fmt.Println(add(a, b)); // cannot use a (type int) as type float64 in argument to add
    fmt.Println(add(1.5, 3.2)); // 4.7
    fmt.Println(add(2.5, 2)); // 4.5
  }
  </code></pre>
  <p>Do I need to convert everything to float (since it &quot;covers&quot; the int range) or do I create a separate functions for each type like <code>addInt(a int, b int) int</code> and <code>addFloat(a float64, b float64) float64</code> or might there be a more elegant way at all?</p>