Complex numbers v0.1.0
Complex
pub struct Complex {
pub real: float64;
pub imaginary: float64;
}
A complex number real + imaginary·i over float64. Copy.
Fields
| Name | Type | Description |
|---|---|---|
real | float64 | The real part. |
imaginary | float64 | The imaginary part. |
Associated functions
New
pub func New(real: float64, imaginary: float64) -> Complex
The number real + imaginary·i.
| Name | Type | Description |
|---|---|---|
real | float64 | the real part |
imaginary | float64 | the imaginary part |
Returns: the number
FromPolar
pub func FromPolar(
magnitude: float64,
angle: float64
) -> Complex
The number with magnitude magnitude at angle radians from the positive real axis.
| Name | Type | Description |
|---|---|---|
magnitude | float64 | the distance from zero |
angle | float64 | the angle in radians |
Returns: the number
Methods
Abs
pub func Abs(self: &Complex) -> float64
The distance from zero, computed without overflow or underflow on the way.
Returns: the magnitude
Arg
pub func Arg(self: &Complex) -> float64
The angle from the positive real axis, in (-π, π].
Returns: the argument in radians
Norm
pub func Norm(self: &Complex) -> float64
The square of the magnitude, which needs no square root.
Returns: the squared magnitude
Conjugate
pub func Conjugate(self: &Complex) -> Complex
The number reflected across the real axis.
Returns: the conjugate
Negate
pub func Negate(self: &Complex) -> Complex
The number with both parts negated.
Returns: the negation
Scale
pub func Scale(self: &Complex, factor: float64) -> Complex
The number with both parts multiplied by factor.
| Name | Type | Description |
|---|---|---|
factor | float64 | the real factor |
Returns: the scaled number
Exp
pub func Exp(self: &Complex) -> Complex
e raised to this number.
Returns: the exponential
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
Sqrt
pub func Sqrt(self: &Complex) -> Complex
The principal square root, whose real part is never negative.
Returns: the square root
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.
| Name | Type | Description |
|---|---|---|
exponent | Complex | the power |
Returns: the power
Operators
+
pub func +(self: &Complex, other: Complex) -> Complex
The sum.
| Name | Type | Description |
|---|---|---|
other | Complex | the number to add |
Returns: the sum
-
pub func -(self: &Complex, other: Complex) -> Complex
The difference.
| Name | Type | Description |
|---|---|---|
other | Complex | the number to subtract |
Returns: the difference
*
pub func *(self: &Complex, other: Complex) -> Complex
The product.
| Name | Type | Description |
|---|---|---|
other | Complex | the number to multiply by |
Returns: the product
/
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.
| Name | Type | Description |
|---|---|---|
other | Complex | the number to divide by |
Returns: the quotient
Complex32
pub struct Complex32 {
pub real: float32;
pub imaginary: float32;
}
A complex number real + imaginary·i over float32. Copy.
Fields
| Name | Type | Description |
|---|---|---|
real | float32 | The real part. |
imaginary | float32 | The imaginary part. |
Associated functions
New
pub func New(real: float32, imaginary: float32) -> Complex32
The number real + imaginary·i.
| Name | Type | Description |
|---|---|---|
real | float32 | the real part |
imaginary | float32 | the imaginary part |
Returns: the number
FromPolar
pub func FromPolar(
magnitude: float32,
angle: float32
) -> Complex32
The number with magnitude magnitude at angle radians from the positive real axis.
| Name | Type | Description |
|---|---|---|
magnitude | float32 | the distance from zero |
angle | float32 | the angle in radians |
Returns: the number
Methods
Abs
pub func Abs(self: &Complex32) -> float32
The distance from zero, computed without overflow or underflow on the way.
Returns: the magnitude
Arg
pub func Arg(self: &Complex32) -> float32
The angle from the positive real axis, in (-π, π].
Returns: the argument in radians
Norm
pub func Norm(self: &Complex32) -> float32
The square of the magnitude, which needs no square root.
Returns: the squared magnitude
Conjugate
pub func Conjugate(self: &Complex32) -> Complex32
The number reflected across the real axis.
Returns: the conjugate
Negate
pub func Negate(self: &Complex32) -> Complex32
The number with both parts negated.
Returns: the negation
Scale
pub func Scale(
self: &Complex32,
factor: float32
) -> Complex32
The number with both parts multiplied by factor.
| Name | Type | Description |
|---|---|---|
factor | float32 | the real factor |
Returns: the scaled number
Exp
pub func Exp(self: &Complex32) -> Complex32
e raised to this number.
Returns: the exponential
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
Sqrt
pub func Sqrt(self: &Complex32) -> Complex32
The principal square root, whose real part is never negative.
Returns: the square root
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.
| Name | Type | Description |
|---|---|---|
exponent | Complex32 | the power |
Returns: the power
Operators
+
pub func +(self: &Complex32, other: Complex32) -> Complex32
The sum.
| Name | Type | Description |
|---|---|---|
other | Complex32 | the number to add |
Returns: the sum
-
pub func -(self: &Complex32, other: Complex32) -> Complex32
The difference.
| Name | Type | Description |
|---|---|---|
other | Complex32 | the number to subtract |
Returns: the difference
*
pub func *(self: &Complex32, other: Complex32) -> Complex32
The product.
| Name | Type | Description |
|---|---|---|
other | Complex32 | the number to multiply by |
Returns: the product
/
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.
| Name | Type | Description |
|---|---|---|
other | Complex32 | the number to divide by |
Returns: the quotient