Documentation ¶
Overview ¶
Package cmplx provides basic constants and mathematical functions for complex numbers.
Index ¶
- func Abs(x complex128) float64
- func Acos(x complex128) complex128
- func Acosh(x complex128) complex128
- func Asin(x complex128) complex128
- func Asinh(x complex128) complex128
- func Atan(x complex128) complex128
- func Atanh(x complex128) complex128
- func Conj(x complex128) complex128
- func Cos(x complex128) complex128
- func Cosh(x complex128) complex128
- func Cot(x complex128) complex128
- func Exp(x complex128) complex128
- func Inf() complex128
- func IsInf(x complex128) bool
- func IsNaN(x complex128) bool
- func Log(x complex128) complex128
- func Log10(x complex128) complex128
- func NaN() complex128
- func Phase(x complex128) float64
- func Polar(x complex128) (r, θ float64)
- func Pow(x, y complex128) complex128
- func Rect(r, θ float64) complex128
- func Sin(x complex128) complex128
- func Sinh(x complex128) complex128
- func Sqrt(x complex128) complex128
- func Tan(x complex128) complex128
- func Tanh(x complex128) complex128
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
func Abs(x complex128) float64
Abs returns the absolute value (also called the modulus) of x.
Example ¶
package main import ( "fmt" "math/cmplx" ) func main() { fmt.Printf("%.1f", cmplx.Abs(3+4i)) }
Output: 5.0
func Exp ¶
func Exp(x complex128) complex128
Exp returns e**x, the base-e exponential of x.
Example ¶
ExampleExp computes Euler's identity.
package main import ( "fmt" "math" "math/cmplx" ) func main() { fmt.Printf("%.1f", cmplx.Exp(1i*math.Pi)+1) }
Output: (0.0+0.0i)
func IsInf ¶
func IsInf(x complex128) bool
IsInf returns true if either real(x) or imag(x) is an infinity.
func IsNaN ¶
func IsNaN(x complex128) bool
IsNaN returns true if either real(x) or imag(x) is NaN and neither is an infinity.
func Phase ¶
func Phase(x complex128) float64
Phase returns the phase (also called the argument) of x. The returned value is in the range [-Pi, Pi].
func Polar ¶
func Polar(x complex128) (r, θ float64)
Polar returns the absolute value r and phase θ of x, such that x = r * e**θi. The phase is in the range [-Pi, Pi].
Example ¶
package main import ( "fmt" "math" "math/cmplx" ) func main() { r, theta := cmplx.Polar(2i) fmt.Printf("r: %.1f, θ: %.1f*π", r, theta/math.Pi) }
Output: r: 2.0, θ: 0.5*π
func Pow ¶
func Pow(x, y complex128) complex128
Pow returns x**y, the base-x exponential of y. For generalized compatibility with math.Pow:
Pow(0, ±0) returns 1+0i Pow(0, c) for real(c)<0 returns Inf+0i if imag(c) is zero, otherwise Inf+Inf i.
func Rect ¶
func Rect(r, θ float64) complex128
Rect returns the complex number x with polar coordinates r, θ.
func Sqrt ¶
func Sqrt(x complex128) complex128
Sqrt returns the square root of x. The result r is chosen so that real(r) ≥ 0 and imag(r) has the same sign as imag(x).
Types ¶
This section is empty.