Guide · 09
Complex numbers
Complex numbers are first-class. Push two doubles, tap ->COMPLEX, and you have a complex card — with arithmetic, trig, transcendentals, and three display modes for the way you want to read the result.
Constructing a complex
Rectangular. Real part, then imaginary part, then ->COMPLEX:
3.0 4.0 ->COMPLEXPolar. Magnitude, then angle, then ->POLAR. The angle is interpreted in the engine’s current angle mode — degrees by default, radians under RAD-MODE, gradians under GRAD-MODE:
5.0 53.13_° ->POLAR # produces the same value as 3.0 4.0 ->COMPLEXCOMPLEX-> pushes the real and imaginary parts back onto the stack as two separate doubles, in reverse construction order — useful for un-packing or for piping into another word.
Display modes
The same complex value displays three different ways depending on the engine mode:
| Word | Mode | 3+4i displays as |
|---|---|---|
MATH-MODE | Math (default) | 3+4i |
POLAR-MODE | Polar | 5∠53.13 |
ENGR-MODE | Engineering | 3+4j |
Switching modes is a display change only — the underlying value is unchanged and can be deparsed losslessly regardless of mode. The Engineering mode substitutes j for i to match the convention used in electrical engineering.
Arithmetic
The standard arithmetic words (+, -, *, /, ^) work on complex values directly. Cross-type with Double and Integer is automatic — the other operand is treated as having zero imaginary part:
3.0 4.0 ->COMPLEX 2.0 * # → 6+8i
3.0 4.0 ->COMPLEX 1.0 0.0 ->COMPLEX + # → 4+4i
2.0 0.5 ->COMPLEX ^ # → 3+4i ^ (2+0.5i)Negation is CHS (change sign) — same word as for any number. Magnitude is ABS (which on a complex returns its MAG).
Extractors
| Word | Pushes | Notes |
|---|---|---|
RE | The real part as a double | |
IM | The imaginary part as a double | |
MAG | The magnitude |z| as a double | Same as ABS |
ARG | The argument (angle) as a double | In the engine’s current angle mode |
All four leave the original complex on NOS untouched if you use DUP first; otherwise they consume it.
Transcendentals, trig, hyperbolics
The full complex math library is registered: SIN, COS, TAN, EXP, LN, LOG, SQRT, SINH, COSH, TANH, and their inverses (ASIN, ACOS, ATAN, ASINH, ACOSH, ATANH). Each dispatches automatically — push a complex, tap the word, get the right result.
Trig honours the angle mode the same way ARG does: under DEG-MODE, SIN of a complex with a “degree-shaped” real part returns what you’d expect; under RAD-MODE, the argument is treated as radians.
0.0 1.0 ->COMPLEX EXP # → cos(0) + i·sin(0) = e^i
3.0 4.0 ->COMPLEX SQRT # → principal square rootEquality
== is strict — 1 1+0i == returns false. Same numerical real value but different types.
EQUIV? is the relaxed sibling — 1 1+0i EQUIV? returns true. Use it when you want to compare across the Complex/Double boundary and treat a Complex with zero imaginary as equivalent to its real component.
Detail card
Tap a complex card to open its detail sheet. You’ll see:
- The real and imaginary parts, with their double-precision values
- The magnitude (
\|z\|) and argument (arg z) — in the current angle mode - The polar form
r∠θ - A quick-pick to switch the display mode for that card without changing the global setting
The detail card is a good place to pivot between rectangular and polar thinking without committing to one mode for the whole session.