
- C++ Library - Home
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ STL Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ Advanced Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ STL Library Cheat Sheet
- C++ STL - Cheat Sheet
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Library -
The
This header provides several functions and macros for handling complex numbers and defines float _Complex, double _Complex, and long double _Complex types.
Including Header
To include the
#include
Functions of Header
Below is list of all functions from
Complex Number Operations
Basic complex number operations in the
S.No | Functions & Description |
---|---|
1 |
real(x)
This function returns the real part of the complex number x. |
2 |
imag(x)
This function returns the imaginary part of the complex number x. |
3 |
abs(x)
This function returns the absolute value of the complex number x. |
4 |
arg(x)
This function returns the phase angle (or angular component) of the complex number x, expressed in radians. |
5 |
norm(x)
This function returns the norm value of the complex number x. |
6 |
conj(x)
This function returns the conjugate of the complex number x. |
7 |
polar(magnitude, angle)
This function returns a complex object (in Cartesian format) corresponding to the complex number using a magnitude and an angle (in radians). |
8 |
proj(x)
This function returns the projection of the complex number x onto the Riemann sphere. |
Basic Manipulations of Complex Numbers
In the following example we are going to use real() and imag() to perform basic manipulations of complex numbers.
#include#include int main() { std::complex z(3.0, 4.0); double real_part = real(z); double imag_part = imag(z); std::cout << "Real part: " << real_part << std::endl; std::cout << "Imaginary part: " << imag_part << std::endl; return 0; }
Output
If we run the above code it will generate the following output
Real part: 3 Imaginary part: 4
Transcendental overloads
The
S.No | Functions & Description |
---|---|
1 |
cos(x)
This function returns the cosine of the complex number x. |
2 |
cosh(x)
This function returns the hyperbolic cosine of the complex number. |
3 |
exp(x)
This function computes the exponential of natural (base-e) logarithm of the complex number x. |
4 |
log10(x)
This function computes the base-10 logarithm of a complex number. |
5 |
pow(x,y)
This function returns the complex power of base x raised to the y-th power. |
6 |
sin(x)
This function returns the sine of the complex number x. |
7 |
sinh(x)
This function returns the hyperbolic sine of the complex number x. |
8 |
sqrt(x)
This function returns the square root of a complex number. |
9 |
tan(x)
This function returns the tangent of the complex number x. |
10 |
cosh(x)
This function returns the hyperbolic cosine of the complex number. |
11 |
tanh(x)
This function returns the hyperbolic tangent of the complex number. |
12 |
acos(x)
This function returns the arc cosine of the complex number x. |
13 |
acosh(x)
This function returns the arc hyperbolic cosine of the complex number x. |
14 |
asinh(x)
This function returns the arc sine of the complex number x. |
15 |
atan(x)
This function returns the arc tangent of the complex number x. |
16 |
atanh(x)
This function returns the arc hyperbolic tangent of the complex number x. |
Using Transcendental Functions
In the following example we are going to use transcendental functions (cos(), exp(), and sqrt()) for a complex number.
#include#include #include int main() { std::complex z(1.0, 2.0); std::complex cos_z = cos(z); std::complex exp_z = exp(z); std::complex sqrt_z = sqrt(z); std::cout << "cos(z) = " << cos_z << std::endl; std::cout << "exp(z) = " << exp_z << std::endl; std::cout << "sqrt(z) = " << sqrt_z << std::endl; return 0; }
Output
If we run the above code it will generate the following output
cos(z) = (2.03272,-3.0519) exp(z) = (-1.1312,2.47173) sqrt(z) = (1.27202,0.786151