Complex numbers v0.1.0

Source
Complex numbers at two precisions: arithmetic, polar form, and the elementary functions.

Complex

pub struct Complex {
    pub real: float64;
    pub imaginary: float64;
}

A complex number real + imaginary·i over float64. Copy.

Source

Fields

NameTypeDescription
realfloat64The real part.
imaginaryfloat64The imaginary part.

Associated functions

New

pub func New(real: float64, imaginary: float64) -> Complex

The number real + imaginary·i.

NameTypeDescription
realfloat64the real part
imaginaryfloat64the imaginary part

Returns: the number

Source

FromPolar

pub func FromPolar(
    magnitude: float64,
    angle: float64
) -> Complex

The number with magnitude magnitude at angle radians from the positive real axis.

NameTypeDescription
magnitudefloat64the distance from zero
anglefloat64the angle in radians

Returns: the number

Source

Methods

Abs

pub func Abs(self: &Complex) -> float64

The distance from zero, computed without overflow or underflow on the way.

Returns: the magnitude

Source

Arg

pub func Arg(self: &Complex) -> float64

The angle from the positive real axis, in (-π, π].

Returns: the argument in radians

Source

Norm

pub func Norm(self: &Complex) -> float64

The square of the magnitude, which needs no square root.

Returns: the squared magnitude

Source

Conjugate

pub func Conjugate(self: &Complex) -> Complex

The number reflected across the real axis.

Returns: the conjugate

Source

Negate

pub func Negate(self: &Complex) -> Complex

The number with both parts negated.

Returns: the negation

Source

Scale

pub func Scale(self: &Complex, factor: float64) -> Complex

The number with both parts multiplied by factor.

NameTypeDescription
factorfloat64the real factor

Returns: the scaled number

Source

Exp

pub func Exp(self: &Complex) -> Complex

e raised to this number.

Returns: the exponential

Source

Log

pub func Log(self: &Complex) -> Complex

The natural logarithm on the principal branch: the logarithm of the magnitude, and the argument.

Returns: the logarithm

Source

Sqrt

pub func Sqrt(self: &Complex) -> Complex

The principal square root, whose real part is never negative.

Returns: the square root

Source

Pow

pub func Pow(self: &Complex, exponent: Complex) -> Complex

This number raised to exponent, as e raised to exponent times the logarithm, so on the principal branch. Zero raised to anything is zero.

NameTypeDescription
exponentComplexthe power

Returns: the power

Source

Operators

+

pub func +(self: &Complex, other: Complex) -> Complex

The sum.

NameTypeDescription
otherComplexthe number to add

Returns: the sum

Source

-

pub func -(self: &Complex, other: Complex) -> Complex

The difference.

NameTypeDescription
otherComplexthe number to subtract

Returns: the difference

Source

*

pub func *(self: &Complex, other: Complex) -> Complex

The product.

NameTypeDescription
otherComplexthe number to multiply by

Returns: the product

Source

/

pub func /(self: &Complex, other: Complex) -> Complex

The quotient, by Smith's method, so that a divisor with very large or very small parts keeps its precision. Dividing by zero gives infinities or NaN, as floating-point division does.

NameTypeDescription
otherComplexthe number to divide by

Returns: the quotient

Source

Complex32

pub struct Complex32 {
    pub real: float32;
    pub imaginary: float32;
}

A complex number real + imaginary·i over float32. Copy.

Source

Fields

NameTypeDescription
realfloat32The real part.
imaginaryfloat32The imaginary part.

Associated functions

New

pub func New(real: float32, imaginary: float32) -> Complex32

The number real + imaginary·i.

NameTypeDescription
realfloat32the real part
imaginaryfloat32the imaginary part

Returns: the number

Source

FromPolar

pub func FromPolar(
    magnitude: float32,
    angle: float32
) -> Complex32

The number with magnitude magnitude at angle radians from the positive real axis.

NameTypeDescription
magnitudefloat32the distance from zero
anglefloat32the angle in radians

Returns: the number

Source

Methods

Abs

pub func Abs(self: &Complex32) -> float32

The distance from zero, computed without overflow or underflow on the way.

Returns: the magnitude

Source

Arg

pub func Arg(self: &Complex32) -> float32

The angle from the positive real axis, in (-π, π].

Returns: the argument in radians

Source

Norm

pub func Norm(self: &Complex32) -> float32

The square of the magnitude, which needs no square root.

Returns: the squared magnitude

Source

Conjugate

pub func Conjugate(self: &Complex32) -> Complex32

The number reflected across the real axis.

Returns: the conjugate

Source

Negate

pub func Negate(self: &Complex32) -> Complex32

The number with both parts negated.

Returns: the negation

Source

Scale

pub func Scale(
    self: &Complex32,
    factor: float32
) -> Complex32

The number with both parts multiplied by factor.

NameTypeDescription
factorfloat32the real factor

Returns: the scaled number

Source

Exp

pub func Exp(self: &Complex32) -> Complex32

e raised to this number.

Returns: the exponential

Source

Log

pub func Log(self: &Complex32) -> Complex32

The natural logarithm on the principal branch: the logarithm of the magnitude, and the argument.

Returns: the logarithm

Source

Sqrt

pub func Sqrt(self: &Complex32) -> Complex32

The principal square root, whose real part is never negative.

Returns: the square root

Source

Pow

pub func Pow(
    self: &Complex32,
    exponent: Complex32
) -> Complex32

This number raised to exponent, as e raised to exponent times the logarithm, so on the principal branch. Zero raised to anything is zero.

NameTypeDescription
exponentComplex32the power

Returns: the power

Source

Operators

+

pub func +(self: &Complex32, other: Complex32) -> Complex32

The sum.

NameTypeDescription
otherComplex32the number to add

Returns: the sum

Source

-

pub func -(self: &Complex32, other: Complex32) -> Complex32

The difference.

NameTypeDescription
otherComplex32the number to subtract

Returns: the difference

Source

*

pub func *(self: &Complex32, other: Complex32) -> Complex32

The product.

NameTypeDescription
otherComplex32the number to multiply by

Returns: the product

Source

/

pub func /(self: &Complex32, other: Complex32) -> Complex32

The quotient, by Smith's method, so that a divisor with very large or very small parts keeps its precision. Dividing by zero gives infinities or NaN, as floating-point division does.

NameTypeDescription
otherComplex32the number to divide by

Returns: the quotient

Source