Complex Numbers

There is a branch of mathematics that deals with numbers consisting of both real and imaginary components—complex numbers. For example, in the real domain, the square root of negative one is undefined, that is, there is no real number that can be multiplied by itself to get -1. However, in the world of complex math, there is a solution to this problem and it is the unit imaginary number called i.

Complex numbers have both a real and imaginary component. In DScript, you enter complex numbers by typing an arithmetic expression using the primitive I. The number 2+3i is entered as 2+3*I or simply 2+3I (multiplication is implied). You can also create complex numbers using formulas that return complex results. For example, the expression sqrt(-1) returns i.

See I.

The two numeric parts of a complex number are each represented by 8-byte floating-point numbers and are stored as a single data item.

There is nothing special you must do to create equations supporting complex math. Almost all mathematical primitives supporting simple real numbers also support complex numbers. Each primitive detects the type of input data you supply and adapts its function to support that data.

Like every other basic capability in DScript, you can ignore the existence of complex numbers if you do not want to use them. However, if you do use complex numbers in work you routinely perform, you will appreciate the ease with which they can be applied in DScript. There is no difference between the way you create formulas using complex and simple real numbers.

All primitives are designed to accept complex numbers if possible. Complex inputs make no sense for some primitives; but for all others, the primitive adapts its function to process complex inputs.

A few primitives are designed explicitly for use with complex numbers. Specifically, use the real and imag primitives to extract the real and imaginary components from a complex number. Use abs and arg to convert complex numbers into their polar equivalent.

See real.

See imag.

See abs.

See arg.