Next: 6.7.3 The character type Up: 6.7 Operators Previous: 6.7.1 The real type Contents

## 6.7.2 The complex type

Complex numbers are rather sketchily implemented. They are generally handy for representing vectors and coordinates rather than for doing arithmetic, so the range of operations is limited.

Complex constants are written as two numbers enclosed in round brackets and separated by a comma. You can use the four standard arithmetic operators (`+`, `-`, `*`, `/`), raise-to-power (`**`), and unary negation and positive (`-`, `+`). You can use `==` only of the relational operators. You can mix complex and real numbers in expressions. You can cast reals to complex and back. Use the functions `re` and `im` to extract the real and imaginary parts.

> | `` | `` |  | `` | `` |  | `` | `` |  | `` | `` |  | `` | `` |  | `` | `` |  | `` | `` |  | `` |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
> | `(12, 13) + 4 == (16, 13)` |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
> | `(12, 2 + 2) == (12, 4)` |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
> | `re (12, 13) == 12` |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
> | `im (12, 13) == 13` |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |

Next: 6.7.3 The character type Up: 6.7 Operators Previous: 6.7.1 The real type Contents