World Library  
Flag as Inappropriate
Email this Article

Complex data type

Article Id: WHEBN0022742157
Reproduction Date:

Title: Complex data type  
Author: World Heritage Encyclopedia
Language: English
Subject: Data types, Record (computer science), Process Environment Block, Quotient type, Product type
Publisher: World Heritage Encyclopedia

Complex data type

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

In some programming environments the term complex data type (in contrast to primitive data types) is a synonym to the composite data type.[1][2]

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

  • The FORTRAN's type COMPLEX
  • The C99 standard of the C programming language includes complex data types and complex math functions in the standard library header <complex.h>
  • The C++ standard library provides a complex templated class as well as complex math functions in the header
  • The Go programming language has built-in types complex64 (each component is 32-bit float) and complex128 (each component is 64-bit float)
  • The Perl core module Math::Complex provides support for complex numbers
  • Python support complex numbers built-in with the type complex. Imaginary number literals can be specified by appending a "j". Complex math functions are provided in the standard library module cmath [3]
  • Ruby provides a Complex class in the standard library module complex
  • OCaml supports complex numbers with the standard library module Complex
  • Haskell supports complex numbers with the standard library module Data.Complex (previously called Complex)
  • Mercury provides complex numbers with full operator overloading support in the extras distribution, using libcomplex_numbers.
  • Java does not have a standard complex number class, but there exists a number of incompatible free implementations of a complex number class:
    • The Apache Commons Math library provides complex numbers for Java with its Complex class
    • The JScience library has a Complex number class
    • 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
  • Common Lisp: The ANSI Common Lisp standard supports complex numbers of floats 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.
  • 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:


The COMPLEX data type was provided in FORTRAN IV.[4]


  1. ^ IBM Informix Database Design and Implementation Guide
  2. ^ Flash 8 Documentation
  3. ^ Python v2.6.5 documentation
  4. ^ 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. "
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.