Complex numbers
A complex number type: the `i` suffix on a number makes it imaginary, arithmetic mixes complex and real values, and every engine (the interpreter, C and wasm) computes the complex functions with the same formulas, so they print the same digits. Run a cell to see its output beside the expected one.
Imaginary literals and arithmetic
2.5i is an imaginary literal (a bare identifier i is still a variable — only digits take the suffix). +, -, *, / work between complex and real values; reals promote.
re, im, conj, abs
abs of a complex number is its modulus; z times its conjugate is exactly |z| squared.
Euler's identity, computed
exp, log, sqrt, sin, cos, tan all work on complex arguments. e^{i pi} comes out as -1 with an imaginary part of 1.2e-16, which is sin of the double nearest pi. sqrt takes the half-angle formulas, so the square root of -1 is exactly i.
A rotation is a complex multiply
Multiplying by e^{i theta} rotates the plane by theta. A function that takes and returns complex values needs no annotations; the compiler infers the types.