Complex data type

Some programming languages provide a complex data type for complex number storage and arithmetic as a built-in (primitive) data type.

Complex-number arithmetic

A complex variable or value is usually represented as a pair of floating-point numbers. Languages that support a complex data type usually provide special syntax for building such values, and extend the basic arithmetic operations ('+', '−', '×', '÷') to act on them. These operations are usually translated by the compiler into a sequence of floating-point machine instructions or into library calls. Those languages may also provide support for other operations, such as formatting, equality testing, etc. As in mathematics, those languages often interpret a floating-point value as equivalent to a complex value with a zero imaginary part.

Language support

 ? (sqrt -1)
# C(0 1)            ; the result of (sqrt -1)

References

  1. ↑ A guide to Fortran IV programming Daniel D. McCracken - 1972 - 288 pages. "The capability provided by Fortran complex operations is a great savings in programming effort in certain problems. "
  2. ↑ "Complex number arithmetic". cppreference.com. Retrieved 2026-04-02.
  3. ↑ "std::complex". cppreference.com. Retrieved 2026-04-02.
  4. ↑ "The Go Programming Language Specification: Numeric types". go.dev. Retrieved 2026-04-02.
  5. ↑ Python v2.6.5 documentation
  6. ↑ "Complex Struct (System.Numerics)". Microsoft Learn. Retrieved 2026-04-02.
  7. ↑ "Complex and Rational Numbers — Julia Language 0.3.13-pre documentation".
  8. ↑ "R Data Types". www.w3schools.com. Retrieved 2022-04-26.