CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Tue, 22 Jul 2025 23:14:55 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/complex/complex/
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 22 Jul 2025 23:14:55 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"738b-6SvUAvimsvPlEksR0Qj8vdE+B+w"
Content-Encoding: gzip
The complex class is designed to hold two elements of the same type representing a complex number in its Cartesian form.
A complex number can be represented by the sum of a real number (
The imaginary part (
In this class, complex numbers have two components: real (corresponding to x in the above example) and imag (corresponding to y).
The class replicates certain functionality aspects of regular numerical types, allowing them to be assigned, compared, inserted and extracted, as well as supporting some arithmetical operators. It is a literal type internally organized as an array of two elements of type T: the first is the real part and the second its imaginary part.
These specializations have the same members as the template, but optimize its implementation for these fundamental types, as well as allowing operations with the other specializations of complex (complex objects with a different template argument).
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
complex
- complex::complex
- complex operators
member functions
class template
<complex>
std::complex
template <class T> class complex;
Complex number class
A complex number can be represented by the sum of a real number (
x
) and an imaginary part (y*i
):x + y * i
The imaginary part (
y*i
) is a factor of i
, known as the imaginary unit, and which satisfies that:i2 = -1
In this class, complex numbers have two components: real (corresponding to x in the above example) and imag (corresponding to y).
The class replicates certain functionality aspects of regular numerical types, allowing them to be assigned, compared, inserted and extracted, as well as supporting some arithmetical operators. It is a literal type internally organized as an array of two elements of type T: the first is the real part and the second its imaginary part.
Template parameters
- T
- Type of both the real and imaginary components of the complex number.
The effect of instantiating a complex with a T other thanfloat
,double
orlong double
is undefined (certain library implementations may support it, but the resulting code is non-portable).
Member types
member type | definition | description |
---|---|---|
value_type | The first template parameter (T) | The type of both Cartesian components |
Member functions
- (constructor)
- Complex number constructor (public member function)
- imag
- Imaginary part (public member function)
- real
- Real part (public member function)
- (operators)
- Complex number operators (function)
Template specializations
complex is specialized for the three fundamental floating-point types:float
, double
and long double
.These specializations have the same members as the template, but optimize its implementation for these fundamental types, as well as allowing operations with the other specializations of complex (complex objects with a different template argument).
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us