42 constexpr
complex(
const T& re = T(),
const T& im = T()) : real(re), imag(im) {
112 template <
typename X>
125 template <
typename X>
127 T ac = real * rhs.
real;
128 T bd = imag * rhs.
imag;
130 T bc = imag * rhs.
real;
131 T ad = real * rhs.
imag;
144 template <
typename X>
146 T ac = real * rhs.
real;
147 T bd = imag * rhs.
imag;
149 T bc = imag * rhs.
real;
150 T ad = real * rhs.
imag;
154 real = (ac + bd) / frac;
155 imag = (bc - ad) / frac;
167 template <
typename T>
178 template <
typename T>
180 return !(lhs == rhs);
188 template <
typename T>
199 template <
typename T>
210 template <
typename T>
221 template <
typename T>
229 return {ac - bd, bc + ad};
238 template <
typename T>
240 return {lhs.
real * rhs, lhs.
imag * rhs};
249 template <
typename T>
251 return {lhs * rhs.
real, lhs * rhs.
imag};
260 template <
typename T>
262 return {lhs.
real / rhs, lhs.
imag / rhs};
271 template <
typename T>
281 return {(ac + bd) / frac, (bc - ad) / frac};
289 template <
typename T>
310 template <
typename T>
323 template <
typename T>
330 return {t, y < T() ? -t : t};
338 return {
std::abs(y) / t, y < T() ? -u : u};
348 template <
typename T>
358 template <
typename T>
364 auto new_arg = z_arg / 3.0f;
374 template <
typename T>
384 template <
typename T>
394 template <
typename T>
404 template <
typename T>
414 template <
typename T>
424 template <
typename T>
434 template <
typename T>
444 template <
typename T>
454 template <
typename T>
464 template <
typename T>
474 template <
typename T>
484 template <
typename T>
494 template <
typename T>
504 template <
typename T>
514 template <
typename T>
524 template <
typename T>
534 template <
typename T>
544 template <
typename T>
554 template <
typename T>
555 inline std::complex<T>
get_conj(
const std::complex<T>& c) {
564 template <
typename T>
575 template <
typename T>
576 std::ostream& operator<<(std::ostream& os, const etl::complex<T>& c) {
577 return os <<
"C(" << c.
real <<
"," << c.
imag <<
")";
complex< T > inverse(complex< T > x)
Returns the inverse of the complex number.
Definition: complex.hpp:475
auto s(T &&value)
Force the evaluation of the given expression.
Definition: stop.hpp:18
auto sin(E &&value) -> detail::unary_helper< E, sin_unary_op >
Apply sinus on each value of the given expression.
Definition: function_expression_builder.hpp:114
auto sinh(E &&value) -> detail::unary_helper< E, sinh_unary_op >
Apply hyperbolic sinus on each value of the given expression.
Definition: function_expression_builder.hpp:144
auto max(L &&lhs, R &&rhs)
Create an expression with the max value of lhs or rhs.
Definition: expression_builder.hpp:65
Complex number implementation.
Definition: complex.hpp:31
auto real()
Extract the real part of a complex expression.
Definition: expression_able.hpp:79
auto log2(E &&value) -> detail::unary_helper< E, log2_unary_op >
Apply logarithm (base 2) on each value of the given expression.
Definition: function_expression_builder.hpp:74
auto sqrt(E &&value) -> detail::unary_helper< E, sqrt_unary_op >
Apply square root on each value of the given expression.
Definition: function_expression_builder.hpp:24
T value_type
The value type.
Definition: complex.hpp:32
bool operator!=(const complex< T > &lhs, const complex< T > &rhs)
Test two complex numbers for inequality.
Definition: complex.hpp:179
auto cosh(E &&value) -> detail::unary_helper< E, cosh_unary_op >
Apply hyperbolic cosinus on each value of the given expression.
Definition: function_expression_builder.hpp:134
auto cbrt(E &&value) -> detail::unary_helper< E, cbrt_unary_op >
Apply cubic root on each value of the given expression.
Definition: function_expression_builder.hpp:44
complex< T > inverse_conj(complex< T > x)
Returns the inverse of the conjugate of the complex number.
Definition: complex.hpp:485
auto operator*(LE &&lhs, RE rhs)
Builds an expression representing the multiplication of lhs and rhs (scalar)
Definition: binary_expression_builder.hpp:149
complex< T > sin(complex< T > z)
Computes the sinus of the complex input.
Definition: complex.hpp:415
auto conj(E &&value)
Apply the conjugate operation on each complex value of the given expression.
Definition: expression_builder.hpp:206
auto abs(E &&value)
Apply absolute on each value of the given expression.
Definition: expression_builder.hpp:54
complex< T > cbrt(complex< T > z)
Computes the complex cubic root of the input.
Definition: complex.hpp:359
complex & operator/=(const complex< X > &rhs)
Divides a complex number.
Definition: complex.hpp:145
auto cos(E &&value) -> detail::unary_helper< E, cos_unary_op >
Apply cosinus on each value of the given expression.
Definition: function_expression_builder.hpp:104
Root namespace for the ETL library.
Definition: adapter.hpp:15
complex & operator+=(const complex< X > &rhs)
Adds a complex number.
Definition: complex.hpp:100
auto tanh(E &&value) -> detail::unary_helper< E, tanh_unary_op >
Apply hyperbolic tangent on each value of the given expression.
Definition: function_expression_builder.hpp:124
complex< T > cosh(complex< T > z)
Computes the hyperbolic cosine of the complex input.
Definition: complex.hpp:445
auto operator+(LE &&lhs, RE &&rhs)
Builds an expression representing the addition of lhs and rhs.
Definition: binary_expression_builder.hpp:38
T get_imag(const std::complex< T > &c)
Returns the imaginary part of the given complex number.
Definition: complex.hpp:515
complex & operator=(const std::complex< T > &rhs) noexcept
Assign a complex number by copy.
Definition: complex.hpp:87
auto invcbrt(E &&value) -> detail::unary_helper< E, invcbrt_unary_op >
Apply inverse cubic root on each value of the given expression.
Definition: function_expression_builder.hpp:54
auto log10(E &&value) -> detail::unary_helper< E, log10_unary_op >
Apply logarithm (base 10) on each value of the given expression.
Definition: function_expression_builder.hpp:84
T abs(complex< T > z)
Computes the magnitude of the given complex number.
Definition: complex.hpp:290
constexpr complex(const complex< X > &rhs)
Construct a complex number by copy from another complex with different inner type.
Definition: complex.hpp:59
auto tan(E &&value) -> detail::unary_helper< E, tan_unary_op >
Apply tangent on each value of the given expression.
Definition: function_expression_builder.hpp:94
complex< T > sqrt(complex< T > z)
Computes the complex square root of the input.
Definition: complex.hpp:324
std::complex< T > get_conj(const std::complex< T > &c)
Returns the conjugate of the given complex number.
Definition: complex.hpp:555
complex & operator*=(const complex< X > &rhs)
Multipliies a complex number.
Definition: complex.hpp:126
T get_real(const std::complex< T > &c)
Returns the real part of the given complex number.
Definition: complex.hpp:535
complex & operator=(const T &rhs) noexcept
Assign a real part to the complex number.
Definition: complex.hpp:68
complex< T > cos(complex< T > z)
Computes the cosine of the complex input.
Definition: complex.hpp:425
complex< T > log(complex< T > z)
Computes the complex logarithm, in base e, of the input.
Definition: complex.hpp:385
complex< T > conj_inverse(complex< T > x)
Returns the conjugate of the inverse of the complex number.
Definition: complex.hpp:495
constexpr complex(const T &re=T(), const T &im=T())
Construct a complex number.
Definition: complex.hpp:42
value_type real
The real part.
Definition: complex.hpp:34
complex< T > conj(const complex< T > &c)
Returns the conjugate of the complex number.
Definition: complex.hpp:505
bool operator==(const complex< T > &lhs, const complex< T > &rhs)
Test two complex numbers for equality.
Definition: complex.hpp:168
value_type imag
The imaginary part.
Definition: complex.hpp:35
auto operator/(LE &&lhs, RE &&rhs)
Builds an expression representing the division of lhs and rhs.
Definition: binary_expression_builder.hpp:77
auto log(E &&value) -> detail::unary_helper< E, log_unary_op >
Apply logarithm (base e) on each value of the given expression.
Definition: function_expression_builder.hpp:64
complex & operator-=(const complex< X > &rhs)
Subtracts a complex number.
Definition: complex.hpp:113
auto invsqrt(E &&value) -> detail::unary_helper< E, invsqrt_unary_op >
Apply inverse square root on each value of the given expression.
Definition: function_expression_builder.hpp:34
complex< T > sinh(complex< T > z)
Computes the hyperbolic sinus of the complex input.
Definition: complex.hpp:455
auto operator-(LE &&lhs, RE &&rhs)
Builds an expression representing the subtraction of lhs and rhs.
Definition: binary_expression_builder.hpp:25
auto imag()
Extract the imag part of a complex expression.
Definition: expression_able.hpp:87
T arg(complex< T > z)
Computes the phase angle of the given complex number.
Definition: complex.hpp:311