Library / Numbers / Numeric types / Complex
Complex
The complex primitive's backing value-class.
Fields 2
number renumber imagConstructors 1
INIT(number re, number imag)
Methods 11
METHOD equals(complex other) RETURNS booleanreads
Component-wise value-equality (the Equatable surface a == b lowers to).
Two complexes are equal iff both components are equal as numbers — so
(3 + 4im) == (3 + 4im). There is NO ordering on complex (</> are a
compile error): the complex field is not ordered.
METHOD __op_plus__(complex other) RETURNS complexreads
Addition / subtraction — component-wise, the reals with the reals and the
imaginaries with the imaginaries: (8 + 6im) = (3 + 4im) + (5 + 2im).
Each component op is ordinary number arithmetic; the result reassembles
through the rp + ip im literal form (fused at parse time, so this does
not recurse into the very operator being defined).
METHOD __op_minus__(complex other) RETURNS complexreads
METHOD __op_times__(complex other) RETURNS complexreads
Multiplication: (a + bi)(c + di) = (ac − bd) + (ad + bc)i. The cross terms
are what make im² = −1 fall out — (0 + 1im) * (0 + 1im) = (−1 + 0im).
METHOD real() RETURNS numberreads
The real component (a in a + bi), as a number.
METHOD imaginary() RETURNS numberreads
The imaginary component (b in a + bi), as a number.
METHOD conjugate() RETURNS complexreads
The complex conjugate — flips the sign of the imaginary part:
conjugate(a + bi) = a − bi. Multiplying a value by its conjugate gives a
real ((a+bi)(a−bi) = a² + b²), which is why division scales by it.
METHOD magnitude() RETURNS numberreads
Magnitude (modulus) |a + bi| = √(a² + b²) — the distance from the origin,
always a non-negative real. Computed in float64 via Math.sqrt, so the
result is a float-subtype number. (Complex depends on Math here.)
METHOD phase() RETURNS numberreads
Phase (argument) of a + bi = atan2(b, a) — the angle in radians from the
positive real axis, in (−π, π]. A float-subtype number.
METHOD negate() RETURNS complexreads
Negation — -c lowers to this: −(a + bi) = (−a) + (−b)i. (Unary minus on
a complex routes here; complex has no C++ unary operator-.)
METHOD __op_divide__(complex other) RETURNS complexreads
Division: (a + bi)/(c + di) = [(ac + bd) + (bc − ad)i] / (c² + d²).
Both components are scaled by the real denominator |other|². With integer
components this follows number's truncating integer /; float-component
complexes divide exactly — use those when an exact quotient is wanted.