math.complex
complex numbers, 2 + 3i; a number touching i is imaginary
Example results generated on 2026-10-08. Ones using
now,todayor randomness will differ when you run them: press Run on any example to run it in your browser, after editing it if you like.
literals
# ni
3i
# a + bi
2 + 3i
operators
# + - * / **
(1 + 2i) * (3 - 1i)
# → 5 + 5i
also takes complex
# abs exp ln sqrt
sqrt(-4 + 0i)
# → 2i
Functions
| function | description |
|---|---|
re(z: num|complex) | real part |
im(z: num|complex) | imaginary part |
conj(z: num|complex) | complex conjugate |
arg(z: num|complex) | angle from the positive real axis, as an angle |
csqrt(z: num|complex) | square root that goes complex for negatives (principal root) |
polar(r: num, theta: num|quantity) / polar(z: num|complex) | a complex number from a length and an angle; with one argument, z in polar form (to polar) |
re
re(z: num|complex): real part
re(2 + 3i)
# → 2
See also: im
im
im(z: num|complex): imaginary part
im(2 + 3i)
# → 3
See also: re
conj
conj(z: num|complex): complex conjugate
conj(2 + 3i)
# → 2 - 3i
arg
arg(z: num|complex): angle from the positive real axis, as an angle
arg(1i) to deg
# → 90 deg
csqrt
csqrt(z: num|complex): square root that goes complex for negatives (principal root)
csqrt(-4)
# → 2i
See also: sqrt
polar
polar(r: num, theta: num|quantity) / polar(z: num|complex): a complex number from a length and an angle; with one argument, z in polar form (to polar)
polar(2, 90 deg)
# → 2i
polar(1i)
# → "polar(1, 90 deg)"
More examples
complex
# Euler's identity
e ** (1i * pi)
# → -1 + 0i
# roots of x² + 2x + 5
[-1 + csqrt(-4) / 2, -1 - csqrt(-4) / 2]
# → [-1 + 1i, -1 - 1i]
# polar form
1 + 1i to polar
# → "polar(1.41421, 45 deg)"