x-lang

← Index

x/num/complex

Complex number arithmetic with rectangular and polar forms.

Literal syntax: a+bi, a-bi (e.g. 3+4i, 0+1i, 2-3i)

Extends arithmetic operators (+, -, *, /, =) with complex promotion.

Arithmetic

Constructors and Accessors

Operator Overrides

Predicates

number?

Test whether a value is any numeric type (integer, rational, float, or complex).

Parameters:

Returns: BOOL — True if x is a number

complex?

Test whether a value is any numeric type (alias for number?).

Parameters:

Returns: BOOL — True if x is a number

real?

Test whether a value is a real number (integer, rational, or float, but not complex).

Parameters:

Returns: BOOL — True if x is a real number

Class Complex

(Complex complex? x)

Test whether a value is any numeric type (alias for number?).

Parameters:

Returns: BOOL — True if x is a number

(Complex make re im)

Construct a complex number from rectangular coordinates.

Parameters:

Returns: COMPLEX|NUMBER — Complex number, or real if imaginary part is zero

(Complex from-polar mag ang)

Construct a complex number from polar coordinates (magnitude and angle).

Parameters:

Returns: COMPLEX|NUMBER — Complex number from polar coordinates

(Complex real-part z)

Return the real part of a complex number, or the number itself for reals.

Parameters:

Returns: NUMBER — Real part

(Complex imag-part z)

Return the imaginary part of a complex number, or 0 for reals.

Parameters:

Returns: NUMBER — Imaginary part

(Complex magnitude z)

Return the magnitude (absolute value) of a complex or real number.

Parameters:

Returns: FLOAT — Absolute value (distance from origin)

(Complex angle z)

Return the angle (argument) of a complex number in radians.

Parameters:

Returns: FLOAT — Angle in radians

(Complex + a b)

Add two complex numbers (reals coerce).

Parameters:

Returns: COMPLEX|NUMBER — Sum, collapsed to real if imaginary part is zero

(Complex - a b)

Subtract two complex numbers (reals coerce).

Parameters:

Returns: COMPLEX|NUMBER — Difference, collapsed to real if imaginary part is zero

(Complex * a b)

Multiply two complex numbers (reals coerce).

Parameters:

Returns: COMPLEX|NUMBER — Product, collapsed to real if imaginary part is zero

(Complex / a b)

Divide two complex numbers (reals coerce).

Parameters:

Returns: COMPLEX|NUMBER — Quotient, collapsed to real if imaginary part is zero

(Complex = a b)

Test whether two complex numbers are equal (reals coerce).

Parameters:

Returns: BOOL — True if both real and imaginary parts are equal