Go math.Abs — absolute value

In Go, math.Abs returns the magnitude of a number. For example, the absolute value of −6 is 6, and the absolute value of 0 is 0.

A simple example

math.Abs

  1. Start with −3
  2. Do this Measure distance from zero
  3. Result 3
From −3, three unit steps reach zero. The magnitude is 3.
main.go
package main

import "fmt"
import "math"

func main() {
    fmt.Println(math.Abs(-3))
}
Output
3