Standard library / math/cmplx

cmplx.Abs()

Magnitude of complex value, computed from both components. Expected stdout: '5\n'.

Formal Syntax & Structure

go syntaxgo
func Abs(x complex128) float64

Parameters & Attributes

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

Return Value

float64

Magnitude of complex value, computed from both components.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/cmplx")
func main() {  fmt.Println(cmplx.Abs(3 + 4i))}
Go Reference