# Module `complex`

## Functions

m.polar (r, theta) | Polar constructor.
m.__eq (a, b) | Exact equality test (no tolerance).
m.__add (a, b) | Addition metamethod.
m.__sub (a, b) | Subtraction metamethod.
m.__mul (a, b) | Multiplication metamethod.
m.__div (a, b) | Division metamethod.
m.__unm (a) | Unary minus metamethod.
m.__tostring (z) | Convert to string in the form `a+bi`.
m.isClose (a, b, eps) | Approximate equality (L¹ norm).
m.distinct (a, b) | Test whether two numbers are distinct (tolerant).
m.nonzero (z) | Test whether a complex number is nonzero (tolerant).
m.det (a, b) | Determinant
m.dot (a, b) | Scalar (dot) product.
m.unit (z) | Normalize to unit modulus.
m.conj (z) | Complex conjugate.
m.abs2 (z) | Squared modulus.
m.abs (z) | Modulus.
m.arg (z) | Argument (principal value).
m.invert (z, center, R) | Complex inversion in circle.
m:isNear (w, eps) | Approximate equality (method form).
m:isNot (w, eps) | Negated approximate comparison (method form).
m:isReal (eps) | Test whether imaginary part is approx.
m:isImag (eps) | Test whether real part is approx.
m:isUnit (eps) | Test whether modulus is approx.
m:isColinear (other, eps) | Test approx.
m:toPolar () | Convert to polar coordinates.
m:clone () | Clone the complex number.
m.exp_i (theta) | e^{iθ}
m:rotate90 () | Rotate by 90 degrees.
m:rotate (theta) | Rotate by angle θ (radians).
m.exp (z) | Complex exponential.
m.log (z) | Principal complex logarithm.

## Fields

m.ONE | 1 + 0i
m.ZERO | 0 + 0i
m.I | i
m.J | Primitive cube root of unity.

## Functions

m.polar (r, theta)
  Polar constructor.

  ### Parameters:

  - r
  - theta
m.__eq (a, b)
  Exact equality test (no tolerance). Use isClose for numerical comparisons.

  ### Parameters:

  - a
  - b
m.__add (a, b)
  Addition metamethod.

  ### Parameters:

  - a
  - b
m.__sub (a, b)
  Subtraction metamethod.

  ### Parameters:

  - a
  - b
m.__mul (a, b)
  Multiplication metamethod.

  ### Parameters:

  - a
  - b
m.__div (a, b)
  Division metamethod.

  ### Parameters:

  - a
  - b

  ### Returns:

  1. nil
  2. string Division by zero.
m.__unm (a)
  Unary minus metamethod.

  ### Parameters:

  - a
m.__tostring (z)
  Convert to string in the form `a+bi`.

  ### Parameters:

  - z
m.isClose (a, b, eps)
  Approximate equality (L¹ norm).

  ### Parameters:

  - a complex
  - b complex
  - eps number optional tolerance

  ### Returns:

  boolean
m.distinct (a, b)
  Test whether two numbers are distinct (tolerant).

  ### Parameters:

  - a
  - b
m.nonzero (z)
  Test whether a complex number is nonzero (tolerant).

  ### Parameters:

  - z
m.det (a, b)
  Determinant

  ### Parameters:

  - a
  - b
m.dot (a, b)
  Scalar (dot) product.

  ### Parameters:

  - a
  - b
m.unit (z)
  Normalize to unit modulus.

  ### Parameters:

  - z

  ### Returns:

  complex|nil nil if zero
m.conj (z)
  Complex conjugate.

  ### Parameters:

  - z
m.abs2 (z)
  Squared modulus.

  ### Parameters:

  - z
m.abs (z)
  Modulus.

  ### Parameters:

  - z
m.arg (z)
  Argument (principal value). Returns angle in radians in (-π, π].

  ### Parameters:

  - z
m.invert (z, center, R)
  Complex inversion in circle.

  ### Parameters:

  - z complex
  - center complex optional
  - R number optional radius
m:isNear (w, eps)
  Approximate equality (method form).

  ### Parameters:

  - w
  - eps
m:isNot (w, eps)
  Negated approximate comparison (method form).

  ### Parameters:

  - w
  - eps
m:isReal (eps)
  Test whether imaginary part is approx. zero (method form).

  ### Parameters:

  - eps
m:isImag (eps)
  Test whether real part is approx. zero (method form).

  ### Parameters:

  - eps
m:isUnit (eps)
  Test whether modulus is approx. 1 (method form).

  ### Parameters:

  - eps
m:isColinear (other, eps)
  Test approx. colinearity with other number (method form).

  ### Parameters:

  - other
  - eps
m:toPolar ()
  Convert to polar coordinates.

  ### Returns:

  1. r number
  2. theta number
m:clone ()
  Clone the complex number.
m.exp_i (theta)
  e^{iθ}

  ### Parameters:

  - theta
m:rotate90 ()
  Rotate by 90 degrees.
m:rotate (theta)
  Rotate by angle θ (radians).

  ### Parameters:

  - theta
m.exp (z)
  Complex exponential.

  ### Parameters:

  - z
m.log (z)
  Principal complex logarithm.

  ### Parameters:

  - z

  ### Returns:

  1. nil
  2. string undefined for 0

## Fields

m.ONE
  1 + 0i
m.ZERO
  0 + 0i
m.I
  i
m.J
  Primitive cube root of unity.

generated by LDoc 1.5.0 Last updated 2026-03-15 16:13:44