Standard library / math

math.Abs()

Magnitude of a real number; NaN propagates and infinity becomes positive. Expected stdout: '3.5\n'.

Formal Syntax & Structure

go syntaxgo
func Abs(x float64) float64

Parameters & Attributes

NameTypeDescription
xfloat64First input operand (or sole input if unary).

Return Value

float64

Magnitude of a real number; NaN propagates and infinity becomes positive.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math")
func main() {  fmt.Println(math.Abs(-3.5))}
Go Reference