package cmplx

import "math/cmplx"

Package cmplx 为复数提供基本常量和数学函数。 特殊情况的处理遵循 C99 标准附录 G 的 IEC 60559 兼容复数运算。

Index

Examples

Functions

func Abs

func Abs(x complex128) float64

Abs 返回 x 的绝对值(也称为模)。

Example
package main

import (
	"fmt"
	"math/cmplx"
)

func main() {
	fmt.Printf("%.1f", cmplx.Abs(3+4i))
}

Output:

5.0

func Acos

func Acos(x complex128) complex128

Acos 返回 x 的反余弦。

func Acosh

func Acosh(x complex128) complex128

Acosh 返回 x 的反双曲余弦。

func Asin

func Asin(x complex128) complex128

Asin 返回 x 的反正弦。

func Asinh

func Asinh(x complex128) complex128

Asinh 返回 x 的反双曲正弦。

func Atan

func Atan(x complex128) complex128

Atan 返回 x 的反正切。

func Atanh

func Atanh(x complex128) complex128

Atanh 返回 x 的反双曲正切。

func Conj

func Conj(x complex128) complex128

Conj 返回 x 的复共轭。

func Cos

func Cos(x complex128) complex128

Cos 返回 x 的余弦。

func Cosh

func Cosh(x complex128) complex128

Cosh 返回 x 的双曲余弦。

func Cot

func Cot(x complex128) complex128

Cot 返回 x 的余切。

func Exp

func Exp(x complex128) complex128

Exp 返回 e**x,即 x 的以 e 为底的指数。

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 Inf

func Inf() complex128

Inf 返回一个复数无穷大,即 complex(+Inf, +Inf)。

func IsInf

func IsInf(x complex128) bool

IsInf 报告 real(x) 或 imag(x) 中是否有一个是无穷大。

func IsNaN

func IsNaN(x complex128) bool

IsNaN 报告 real(x) 或 imag(x) 中是否有一个是 NaN 且两者都不是无穷大。

func Log

func Log(x complex128) complex128

Log 返回 x 的自然对数。

func Log10

func Log10(x complex128) complex128

Log10 返回 x 的十进制对数。

func NaN

func NaN() complex128

NaN 返回一个复数“非数”(not-a-number)值。

func Phase

func Phase(x complex128) float64

Phase 返回 x 的相位(也称为辐角)。 返回值在区间 [-Pi, Pi] 内。

func Polar

func Polar(x complex128) (r, θ float64)

Polar 返回 x 的绝对值 r 和相位 θ, 使得 x = r * e**θi。 相位在区间 [-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 返回 x**y,即以 x 为底 y 的指数。 为了与 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 返回具有极坐标 r、θ 的复数 x。

func Sin

func Sin(x complex128) complex128

Sin 返回 x 的正弦。

func Sinh

func Sinh(x complex128) complex128

Sinh 返回 x 的双曲正弦。

func Sqrt

func Sqrt(x complex128) complex128

Sqrt 返回 x 的平方根。 结果 r 的选取使得 real(r) ≥ 0 且 imag(r) 与 imag(x) 具有相同的符号。

func Tan

func Tan(x complex128) complex128

Tan 返回 x 的正切。

func Tanh

func Tanh(x complex128) complex128

Tanh 返回 x 的双曲正切。