Complex data type

From Wikipedia, the free encyclopedia

Script error: No such module "For". Some programming languages provide a complex data type for complex number storage and arithmetic as a built-in (primitive) data type.

Complex-number arithmetic

Page Module:Message box/ambox.css has no content.

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

Page Module:Message box/ambox.css has no content.

  • The FORTRAN COMPLEX type.[1]
  • The C99 standard of the C programming language includes complex data types and complex-math functions in the standard library header <complex.h>.[2]
  • The C++ standard library provides a complex template class as well as complex-math functions in the <complex> header.[3]
  • The Go programming language has built-in types complex64 (each component is 32-bit float) and complex128 (each component is 64-bit float). Imaginary number literals can be specified by appending an "i".[4]
  • The Perl core module Page Template:Mono/styles.css has no content.Math::Complex provides support for complex numbers.
  • Python provides the built-in complex type. Imaginary number literals can be specified by appending a "j". Complex-math functions are provided in the standard library module cmath.[5]
  • Ruby provides a Page Template:Mono/styles.css has no content.Complex class in the standard library module Page Template:Mono/styles.css has no content.complex.
  • OCaml supports complex numbers with the standard library module Page Template:Mono/styles.css has no content.Complex.
  • Haskell supports complex numbers with the standard library module Page Template:Mono/styles.css has no content.Data.Complex (previously called Page Template:Mono/styles.css has no content.Complex).
  • Mercury provides complex numbers with full operator overloading support in the extras distribution, using Page Template:Mono/styles.css has no content.libcomplex_numbers.
  • Java does not have a standard complex number class, but there exist a number of incompatible free implementations of a complex number class:
  • Common Lisp: The ANSI Common Lisp standard supports complex numbers of floats, rationals and arbitrary precision integers. Its basic mathematical functions are defined for complex numbers, where applicable. For example the square root of −1 is a complex number:
 ? (sqrt -1)
# C(0 1)            ; the result of (sqrt -1)
  • Scheme: Complex numbers and functions (e.g. sin) are included in the language specification. Their implementation is however optional in the R5RS standard, while in R6RS is mandatory.
  • The .NET Framework provides System.Numerics.Complex since version 4.0.[6]
  • The smart BASIC for iOS naturally supports complex numbers in notation a + bi. Any variable, math operation or function can accept both real and complex numbers as arguments and return real or complex numbers depending on result. For example the square root of −4 is a complex number:
    PRINT SQRT(-4)
    2i
    
  • Julia includes predefined types for both complex and rational numbers since at least version 0.3.[7]
  • R provides a complex basic data type.[8]
  • Rust does not provide a built-in complex data type, but multiple crates, that add support for such types, exist.
  • Swift does not have a standard complex number data type, but Swift Numerics which is maintained by the language maintainers offers ComplexModule.

Integration in programming

Many programming languages provide built-in support or standard libraries for complex data types, enabling direct manipulation of complex numbers in code. These integrations typically define arithmetic operations, comparison rules, and input/output formatting specific to complex numbers. For example, in Python, the complex type allows arithmetic with complex literals and supports functions from the cmath module.[9] Similarly, Haskell includes the Data.Complex module, offering complex arithmetic with real and imaginary parts represented as floating-point numbers.[10] Such integration simplifies scientific and engineering computations that require complex number calculations.


References

Page Template:Reflist/styles.css has no content.

  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. ^ Page Module:Citation/CS1/styles.css has no content."Complex number arithmetic". cppreference.com. Retrieved 2026-04-02.
  3. ^ Page Module:Citation/CS1/styles.css has no content."std::complex". cppreference.com. Retrieved 2026-04-02.
  4. ^ Page Module:Citation/CS1/styles.css has no content."The Go Programming Language Specification: Numeric types". go.dev. Retrieved 2026-04-02.
  5. ^ Python v2.6.5 documentation
  6. ^ Page Module:Citation/CS1/styles.css has no content."Complex Struct (System.Numerics)". Microsoft Learn. Retrieved 2026-04-02.
  7. ^ Page Module:Citation/CS1/styles.css has no content."Complex and Rational Numbers — Julia Language 0.3.13-pre documentation".
  8. ^ Page Module:Citation/CS1/styles.css has no content."R Data Types". www.w3schools.com. Retrieved 2022-04-26.
  9. ^ Page Module:Citation/CS1/styles.css has no content."Built-in Types: complex". Python documentation. Retrieved 2025-06-14.
  10. ^ Page Module:Citation/CS1/styles.css has no content."Haskell 2010 Language Report: Data.Complex module". Haskell.org. Retrieved 2025-06-14.

Lua error in package.lua at line 80: module 'Module:Navbox/configuration' not found.