Someprogramming languages provide acomplex data type forcomplex number storage and arithmetic as a built-in (primitive)data type.
This sectiondoes notcite anysources. Please helpimprove this section byadding citations to reliable sources. Unsourced material may be challenged andremoved.(June 2023) (Learn how and when to remove this message) |
A complex variable or value is usually represented as a pair offloating-point numbers. Languages that support a complex data type usually provide special syntax for building such values, and extend the basicarithmetic operations ('+', '−', '×', '÷')to act on them. These operations are usually translated by thecompiler into a sequence of floating-pointmachine instructions or intolibrary calls. Those languages may also provide support for other operations, such as formatting, equality testing, etc. As inmathematics, those languages often interpret a floating-point value as equivalent to a complex value with a zero imaginary part.
This sectionneeds expansion. You can help byadding missing information.(November 2015) |
<complex.h>.complex template class as well as complex-math functions in the<complex> header.complex64 (each component is 32-bit float) andcomplex128 (each component is 64-bit float). Imaginary number literals can be specified by appending an "i".complex type. Imaginary number literals can be specified by appending a "j". Complex-math functions are provided in the standard library modulecmath.[2]?(sqrt-1)#C(01); the result of (sqrt -1)
sin) are included in the language specification. Their implementation is however optional in the R5RS standard, while in R6RS is mandatory.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:PRINTSQRT(-4)2i
complex basic data type.[4]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, thecomplex type allows arithmetic with complex literals and supports functions from thecmath module.[5] Similarly, Haskell includes theData.Complex module, offering complex arithmetic with real and imaginary parts represented as floating-point numbers.[6] Such integration simplifies scientific and engineering computations that require complex number calculations.