Complex
classin packageklyn.math
public class Complex<FLOAT_TYPE extends AbstractFloat = Double> extends AbstractNumber
Complex

Represents a complex number with real and imaginary parts. Arithmetic operators require non-null complex operands: proven-null values are rejected with TypeError, and unknown null values with NullException.

Example
z = Complex<Double>(3.0, 4.0)
print(z.magnitude())   # 5.0
Properties
Modifier and Type Member Description
public property imag
imag as FLOAT_TYPE
The imaginary part of the complex number.
public property real
real as FLOAT_TYPE
The real part of the complex number.
Constructors
Modifier and Type Member Description
public Complex
Complex(real as FLOAT_TYPE = FLOAT_TYPE(0), imaginary as FLOAT_TYPE = FLOAT_TYPE(0))
Constructor for Complex class.
Methods
Modifier and Type Member Description
public conjugate
conjugate() as Complex<FLOAT_TYPE>
Returns the conjugate of the complex number.
public magnitude
magnitude() as Double
Returns the magnitude (or absolute value) of the complex number.
public phase
phase() as Double
Returns the phase (or angle) of the complex number in radians.
public override toString
toString() as String
Returns a string representation of the complex number.
Operators
Modifier and Type Member Description
public static operator*( notnull c1 as Complex<FLOAT_TYPE>, notnull c2 as Complex<FLOAT_TYPE> ) as Complex<FLOAT_TYPE> Multiplication operator for Complex numbers.
public static operator*(notnull c1 as Complex<FLOAT_TYPE>, value as FLOAT_TYPE) as Complex<FLOAT_TYPE> Scales both components without allocating an intermediate complex value.
public static operator*(value as FLOAT_TYPE, notnull c1 as Complex<FLOAT_TYPE>) as Complex<FLOAT_TYPE> Multiplies a scalar by a complex value.
public static operator+( notnull c1 as Complex<FLOAT_TYPE>, notnull c2 as Complex<FLOAT_TYPE> ) as Complex<FLOAT_TYPE> Addition operator for Complex numbers.
public static operator+( notnull c1 as Complex<FLOAT_TYPE>, value as FLOAT_TYPE ) as Complex<FLOAT_TYPE> Addition operator between a complex number and a scalar value.
public static operator+( value as FLOAT_TYPE, notnull c1 as Complex<FLOAT_TYPE> ) as Complex<FLOAT_TYPE> Addition operator between a scalar value and a complex number.
public static operator-( notnull c1 as Complex<FLOAT_TYPE>, notnull c2 as Complex<FLOAT_TYPE> ) as Complex<FLOAT_TYPE> Subtraction operator for Complex numbers.
public static operator-( notnull c1 as Complex<FLOAT_TYPE>, value as FLOAT_TYPE ) as Complex<FLOAT_TYPE> Subtraction operator between a complex number and a scalar value.
public static operator-( value as FLOAT_TYPE, notnull c1 as Complex<FLOAT_TYPE> ) as Complex<FLOAT_TYPE> Subtraction operator between a scalar value and a complex number.
public static operator/( notnull c1 as Complex<FLOAT_TYPE>, notnull c2 as Complex<FLOAT_TYPE> ) as Complex<FLOAT_TYPE> Division operator for Complex numbers.
public static operator/(notnull c1 as Complex<FLOAT_TYPE>, value as FLOAT_TYPE) as Complex<FLOAT_TYPE> Divides each component by a scalar, avoiding a temporary divisor object.
public static operator/(value as FLOAT_TYPE, notnull c1 as Complex<FLOAT_TYPE>) as Complex<FLOAT_TYPE> Divides a scalar by a complex number without creating a temporary numerator.