Previous: Floating-Point Numbers, Up: Scalars [Contents][Index]

Complex numbers consist of two parts, called the *real* part and
the *imaginary* part. A complex number that has no imaginary part
is called a real number; A complex number that has no real part is
called an imaginary number. Any imaginary number can be written as the
product of a real number and the *imaginary unit*. The imaginary
unit is generally denoted `i`

in mathematical notation and `j`

in engineering texts, and is available in LUX as read-only variable
`#i`

, and as suffix `i`

or `I`

on any non-imaginary
number: `2*#i`

and `2i`

are two ways of expressing twice the
imaginary unit. The imaginary unit is defined such that
`#i^2 = -1`

.

Complex numbers come in two data types: complex float (`cfloat`

),
and complex double (`cdouble`

). `cdouble`

is explicitly
indicated by use of the `D`

specifier (for `double`

) and the
`I`

specifier (for imaginary).

Complex numbers have no natural ordering, so there is no obvious way
to decide whether a complex number `x`

is less than or greater
than another complex number `y`

. If `x = a + b*#i`

and
`y = c + d*#i`

where `a, b, c, d`

are real (non-complex)
numbers, then we adopt the rule that `x > y`

if ```
a + b > c +
d
```

, and `x < y`

if `a + b < c + d`

. With that rule, the
ordering of `cfloat`

or `cdouble`

numbers with their
imaginary part equal to 0 (i.e., so-called purely imaginary numbers)
is the same as the ordering of the corresponding `float`

or
`double`

numbers (e.g., `1+0i GT -2+0i`

, just like ```
1
GT -2
```

), and the ordering of complex numbers with their real part
equal to 0 is similar to that of real numbers (e.g., ```
1i GT
-2i
```

).

However, any such rule can lead to somewhat unusual results. For real
(non-complex) numbers, if both `x LT y`

and `x GT y`

are
false, then `x EQ y`

must be true, and vice versa. For complex
numbers, that relationship does not necessarily hold anymore. For
example, with the above rule, `x LT y`

and `x GT y`

and
`x EQ y`

are all false if `x = 3+2i`

and `y = 8-3i`

,
because 3+2 is equal to 8-3. So, even though `x`

is not less
than `y`

, and `x`

is not greater than `y`

, yet `x`

is not equal to `y`

.

The abovementioned ordering rule for complex numbers is used by the
binary relational operators `lt`

, `le`

, `gt`

,
`ge`

, and also by the binary bounding operators `>`

,
`<`

.

See also: #i, abs, real, imaginary, conjugate, fft, Binary Relationals, Binary Bounding

Previous: Floating-Point Numbers, Up: Scalars [Contents][Index]