Standard library / math/cmplx

cmplx.Sqrt()

Principal square root, including imaginary results for negative reals. Expected stdout: '0 2\n'.

Formal Syntax & Structure

go syntaxgo
func Sqrt(x complex128) complex128

Parameters & Attributes

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

Return Value

complex128

Principal square root, including imaginary results for negative reals.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/cmplx")
func main() {  z := cmplx.Sqrt(-4)  fmt.Printf("%.6g %.6g\n", real(z)+0.0, imag(z)+0.0)}
Go Reference