Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Complex data type

From Wikipedia, the free encyclopedia
For the concept sometimes also called "complex data type", seecomposite data type.

Someprogramming languages provide acomplex data type forcomplex number storage and arithmetic as a built-in (primitive)data type.

Complex-number arithmetic

[edit]
icon
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.

Language support

[edit]
[icon]
This sectionneeds expansion. You can help byadding missing information.(November 2015)
  • TheFORTRAN COMPLEX type.[1]
  • TheC99 standard of the C programming language includes complex data types and complex-math functions in the standard library header<complex.h>.
  • TheC++ standard library provides acomplex template class as well as complex-math functions in the<complex> header.
  • TheGo programming language has built-in typescomplex64 (each component is 32-bit float) andcomplex128 (each component is 64-bit float). Imaginary number literals can be specified by appending an "i".
  • ThePerl core moduleMath::Complex provides support for complex numbers.
  • Python provides the built-incomplex type. Imaginary number literals can be specified by appending a "j". Complex-math functions are provided in the standard library modulecmath.[2]
  • Ruby provides aComplex class in the standard library modulecomplex.
  • OCaml supports complex numbers with the standard library moduleComplex.
  • Haskell supports complex numbers with the standard library moduleData.Complex (previously calledComplex).
  • Mercury provides complex numbers with full operator overloading support in the extras distribution, usinglibcomplex_numbers.
  • Java does not have a standard complex number class, but there exist a number of incompatible free implementations of a complex number class:
    • TheApache Commons Math library provides complex numbers for Java with itsComplex class.
    • TheJScience library has aComplex number class.
    • TheJAS library allows the use of complex numbers.
    • Netlib has a complex number class for Java.
    • javafastcomplex also adds complex number support for Java.
    • jcomplexnumber is a project on implementation of complex number in Java.
    • JLinAlg includes complex numbers with arbitrary precision.
  • 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(01); 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 providesSystem.Numerics.Complex since version 4.0.
  • Thesmart BASIC foriOS naturally supports complex numbers in notationa + 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
  • Julia includes predefined types for both complex and rational numbers since at least version 0.3.[3]
  • R provides acomplex basic data type.[4]
  • 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, butSwift Numerics which is maintained by the language maintainers offersComplexModule.

Integration in programming

[edit]

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.


References

[edit]
  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. ^Python v2.6.5 documentation
  3. ^"Complex and Rational Numbers — Julia Language 0.3.13-pre documentation".
  4. ^"R Data Types".www.w3schools.com. Retrieved2022-04-26.
  5. ^"Built-in Types: complex".Python documentation. Retrieved2025-06-14.
  6. ^"Haskell 2010 Language Report: Data.Complex module".Haskell.org. Retrieved2025-06-14.
Uninterpreted
Numeric
Reference
Text
Composite
Other
Related
topics
Retrieved from "https://en.wikipedia.org/w/index.php?title=Complex_data_type&oldid=1328303026"
Category:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp