Complex Number¶
A complex number is a number that can be expressed in the form a + bi
, where a
and b
are real numbers, and i
is a solution of the equation x^2 = -1
. Because no real number satisfies this equation, i
is called an imaginary number. For the complex number a + bi
, a
is called the real part, and b
is called the imaginary part. The set of complex numbers is denoted by \(\mathbb{C}\).
Conjugate & Norm¶
The norm of a complex number is defined as the square of the self with conjugated self. The conjugate of a complex number is the same as the original number, but the sign of the imaginary part is flipped.
Addition, Subtraction¶
Addition and subtraction of complex numbers are defined as follows:
Multiplication¶
Multiplication of complex numbers is defined as follows:
Inverse & Division¶
Division is defined as multiplication by the inverse of the divisor:
Complex Number Class¶
// initializer, 1+2i
ComlexNum<float> z1{1.f, 2.f}; // Re, Im
ComplexNum<float> z2{{1.f, 2.f}};
// type alias
ComplexNumf z3 = z1
// cast to other object (2 x 1)
Vectorf<2> vec21 = z1.cast2Vector();
Matrixf<2,1> mat21 = z1.cast2Matrix();
z1 = vec21.cast2ComplexNum();
// accessor
float re = z1.re();
float im = z1.im();
z1.Re() = re;
z1.Im() = im;
// conjugate
ComplexNumf z1_conj = z1.conjugated();
// norm
float norm = z1.norm();
float normSq = z1.normSquared();
ComplexNumf z1_normed = z1.normalized();
// inverse
ComplexNumf z1_inv = z1.inversed();
// operators
ComplexNumf z3 = z1 + z2;
ComplexNumf z4 = z1 - z2;
ComplexNumf z5 = z1 * z2; // complex number multiplication
ComplexNumf z6 = z1 / z2; // z1 * z2.inversed()
// result type casting
Vectorf<2> vec21 = SquareMatirxf<2>{} * z1; // matrix multiplication
// to multiplication matrix
SquareMatrixf<2> mat2 = z1.toMulMatrix();
// | Re(), -Im() |
// | Im(), Re() |