Complex number

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  or   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. 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  complex array to a shape   real array where each row contains the components of one complex number. Operations on real numbers can sometimes yield complex numbers. Famously, the square root of minus one is the imaginary unit:

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.


 * APL2
 * SHARP APL (but not SAX)
 * Dyalog APL
 * J
 * NARS2000
 * GNU APL
 * ngn/apl