# Complex number

(Redirected from Complex)

A complex number type is a numeric type which represents, usually with some limited precision, the complex numbers. Complex number support is defined as an optional facility in the XAPL standard (ISO/IEC 13751:2001), and complex numbers are available in many APLs. Usually these numbers are written with a syntax such as `5j2` or `5J2` for the complex number with real part 5 and imaginary part 2.

## Examples

Complex numbers are usually written with a "J" joining the real and imaginary parts. Complex numbers are added component-wise.

```      1J¯2 + 3J4
4J2```

The Circle function can be used to split a complex number into its components: a left argument of 9 gets the real part and a left argument of 11 gets the imaginary part. With the Rank operator, Circle can be used to convert a shape `s` complex array to a shape `s,2` real array where each row contains the components of one complex number.

```      9 11 ○ 12J3
12 3
9 11∘○⍤0 ⊢6J5 4J3 2J1
6 5
4 3
2 1```

Operations on real numbers can sometimes yield complex numbers. Famously, the square root of minus one is the imaginary unit:

```      ¯1*÷2
0J1```

## Implementation

Complex numbers are almost always defined to be a pair of 64-bit floating point numbers (IEEE 754). If 64-bit floats are used for real numbers as well then this definition makes complex numbers a superset of the real numbers as represented. This means that the language semantics can be defined purely in terms of complex numbers. However, for performance and precision reasons, operations are implemented both on real numbers and complex numbers. If all the numbers in an array have imaginary part zero, then it is represented as a real array (or a smaller type such as integer), and primitives applied to it will use code written specifically for real numbers.

## Support

The following languages support complex numbers as a built in numeric type.

APL features 
Built-ins Primitives (functions, operators) ∙ Quad name
Array model ShapeRankDepthBoundIndex (Indexing) ∙ AxisRavelRavel orderElementScalarVectorMatrixSimple scalarSimple arrayNested arrayCellMajor cellSubarrayEmpty arrayPrototype
Data types Number (Boolean, Complex number) ∙ Character (String) ∙ BoxNamespaceFunction array
Concepts and paradigms Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity elementComplex floorTotal array orderingTacit programming (Function composition, Close composition) ∙ Glyph
Errors LIMIT ERRORRANK ERRORSYNTAX ERRORDOMAIN ERRORLENGTH ERRORINDEX ERRORVALUE ERROR