title: Why doesn't Go have a function to calculate the absolute value of integers?
body: <p>In Go, why is there no function which directly calculates absolute value for integer datatypes? Currently all integer values have to be typecast to <code>float64</code> and then passed to <code>math.Abs()</code>, which returns a <code>float64</code>, which again has to be typecast into an integer.</p>
  <p>This code raises a <code>./prog.go:12:39: cannot use x (type int64) as type float64 in argument to math.Abs</code> error because Go is a statically typed language, so it does not allow a different datatype:</p>
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;math&quot;
  )
  
  func main() {
      fmt.Println(&quot;Hello, playground&quot;)
      var x int64 = -10
      
      fmt.Println(&quot;Abolute value &quot;, math.Abs(x))  
  }
  </code></pre>