4.2 Complex constructors and accessors
4.2.1 Complex constructors
Variables and constants of type complex
are constructed from zero,
one, or two real numbers.
complex z1 = to_complex(); // z1 = 0.0 + 0.0i
real re = -2.9;
complex z2 = to_complex(re); // z2 = -2.9 + 0.0i
real im = 1.3;
complex z3 = to_complex(re, im); // z3 = -2.9 + 1.3i
complex
to_complex
()
Return complex number with real part 0.0 and imaginary part 0.0.
Available since 2.28
complex
to_complex
(real re)
Return complex number with real part re
and imaginary part 0.0.
Available since 2.28
complex
to_complex
(real re, real im)
Return complex number with real part re
and imaginary part im
.
Available since 2.28
Z
to_complex
(T1 re, T2 im)
Vectorized implementation of the to_complex
function.
T1
and T2
can either be real containers of the same size, or a real
container and a real, in which case the real value is used for the corresponding
component in all elements of the output.
Available since 2.30
4.2.2 Complex accessors
Given a complex number, its real and imaginary parts can be extracted with the following functions.
real
get_real
(complex z)
Return the real part of the complex number z
.
Available since 2.28
real
get_imag
(complex z)
Return the imaginary part of the complex number z
.
Available since 2.28