complex

Complex Number Arithmetic

Functions

FunctionDescription
cx_newCreate complex number.
cx_addAdd two complex numbers.
cx_subSubtract: a - b.
cx_mulMultiply: (a+bi)(c+di) = (ac-bd) + (ad+bc)i.
cx_scaleScalar multiply.
cx_abs_sqMagnitude squared:
cx_conjugateComplex conjugate.
cx_eqEquality check.
cx_reReal part.
cx_imImaginary part.
cx_is_realCheck if purely real.
_cx_write_intInternal: write integer to buffer. Returns chars written.
cx_to_strFormat as string: “a+bi” or “a-bi”. Returns length.

Details

cx_new

fn cx_new(re: i64, im: i64) -> &i64

Create complex number.

cx_add

fn cx_add(a: &i64, b: &i64) -> &i64

Add two complex numbers.

cx_sub

fn cx_sub(a: &i64, b: &i64) -> &i64

Subtract: a - b.

cx_mul

fn cx_mul(a: &i64, b: &i64) -> &i64

Multiply: (a+bi)(c+di) = (ac-bd) + (ad+bc)i.

cx_scale

fn cx_scale(a: &i64, k: i64) -> &i64

Scalar multiply.

cx_abs_sq

fn cx_abs_sq(a: &i64) -> i64

Magnitude squared: |a|^2 = re^2 + im^2.

cx_conjugate

fn cx_conjugate(a: &i64) -> &i64

Complex conjugate.

cx_eq

fn cx_eq(a: &i64, b: &i64) -> i64

Equality check.

cx_re

fn cx_re(a: &i64) -> i64

Real part.

cx_im

fn cx_im(a: &i64) -> i64

Imaginary part.

cx_is_real

fn cx_is_real(a: &i64) -> i64

Check if purely real.

_cx_write_int

fn _cx_write_int(val: i64, out: &i8, off: i64) -> i64

Internal: write integer to buffer. Returns chars written.

cx_to_str

fn cx_to_str(a: &i64, out: &i8) -> i64

Format as string: “a+bi” or “a-bi”. Returns length.