3#ifndef TETL_COMPLEX_COMPLEX_HPP
4#define TETL_COMPLEX_COMPLEX_HPP
22 constexpr complex(T
const& re = T(), T
const& im = T());
32 [[nodiscard]]
constexpr auto real() const -> T;
33 constexpr auto
real(T val) ->
void;
35 [[nodiscard]] constexpr auto
imag() const -> T;
36 constexpr auto
imag(T val) ->
void;
38 constexpr auto operator+=(T const& val) ->
complex<T>&;
39 constexpr auto operator-=(T const& val) ->
complex<T>&;
40 constexpr auto operator*=(T const& val) ->
complex<T>&;
41 constexpr auto operator/=(T const& val) ->
complex<T>&;
52 template <
size_t I, typename X>
53 friend constexpr auto
get(
complex<X>&) noexcept -> X&;
55 template <
size_t I, typename X>
56 friend constexpr auto
get(
complex<X>&&) noexcept -> X&&;
58 template <
size_t I, typename X>
59 friend constexpr auto
get(
complex<X> const&) noexcept -> X const&;
61 template <
size_t I, typename X>
62 friend constexpr auto
get(
complex<X> const&&) noexcept -> X const&&;
64 friend constexpr auto operator==(
complex const& lhs,
complex const& rhs) ->
bool
66 return lhs.real() == rhs.real() and lhs.imag() == rhs.imag();
71 return lhs.real() == rhs and lhs.imag() == T{};
85template <
size_t I,
typename T>
87 static_assert(I < 2,
"Index out of range for etl::complex");
91template <
size_t I,
typename X>
94 static_assert(I < 2,
"Index out of range for etl::complex");
95 if constexpr (I == 0) {
102template <
size_t I,
typename X>
105 static_assert(I < 2,
"Index out of range for etl::complex");
106 if constexpr (I == 0) {
113template <
size_t I,
typename X>
116 static_assert(I < 2,
"Index out of range for etl::complex");
117 if constexpr (I == 0) {
124template <
size_t I,
typename X>
127 static_assert(I < 2,
"Index out of range for etl::complex");
128 if constexpr (I == 0) {
145 : _real{static_cast<T>(other.
real())}
146 , _imag{static_cast<T>(other.
imag())}
232 auto const r =
static_cast<T
>(_real * val.real() - _imag * val.imag());
233 _imag =
static_cast<T
>(_real * val.imag() + _imag * val.real());
242 auto const norm = [](
auto const& c) {
243 auto const x = c.real();
244 auto const y = c.imag();
245 return static_cast<T
>(x * x + y * y);
248 auto const r =
static_cast<T
>(_real * val.real() + _imag * val.imag());
249 auto const n =
norm(val);
250 _imag = (_imag * val.real() - _real * val.imag()) / n;
264 return {
static_cast<T
>(-val.real()),
static_cast<T
>(-val.imag())};
340inline namespace literals {
343constexpr auto operator""_il(
long double d) ->
complex<long double> {
return {0.0L,
static_cast<long double>(d)}; }
347 return {0.0L,
static_cast<long double>(d)};
350constexpr auto operator""_i(
long double d) ->
complex<double> {
return {0.0,
static_cast<double>(d)}; }
352constexpr auto operator""_i(
unsigned long long d) ->
complex<double> {
return {0.0,
static_cast<double>(d)}; }
354constexpr auto operator""_if(
long double d) ->
complex<float> {
return {0.0F,
static_cast<float>(d)}; }
356constexpr auto operator""_if(
unsigned long long d) ->
complex<float> {
return {0.0F,
static_cast<float>(d)}; }
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
constexpr auto norm(complex< T > const &z) noexcept -> T
Definition norm.hpp:14
constexpr auto real(complex< T > const &z) noexcept(noexcept(z.real())) -> T
Definition real.hpp:14
constexpr auto imag(complex< T > const &z) noexcept(noexcept(z.imag())) -> T
Definition imag.hpp:14
Definition complex.hpp:341
Definition adjacent_find.hpp:8
constexpr auto is_tuple_like
Definition is_tuple_like.hpp:9
constexpr auto get(complex< X > &z) noexcept -> X &
Definition complex.hpp:92
constexpr auto operator-(complex< T > const &val) -> complex< T >
Definition complex.hpp:262
constexpr auto operator+(complex< T > const &val) -> complex< T >
Definition complex.hpp:256
constexpr auto operator/(complex< T > const &lhs, complex< T > const &rhs) -> complex< T >
Definition complex.hpp:322
constexpr auto operator*(complex< T > const &lhs, complex< T > const &rhs) -> complex< T >
Definition complex.hpp:304
A complex number.
Definition complex.hpp:19
constexpr auto operator/=(T const &val) -> complex< T > &
Definition complex.hpp:204
friend constexpr auto get(complex< X > &) noexcept -> X &
Definition complex.hpp:92
constexpr auto operator-=(T const &val) -> complex< T > &
Definition complex.hpp:190
constexpr auto imag() const -> T
Definition complex.hpp:163
constexpr complex(T const &re=T(), T const &im=T())
Definition complex.hpp:136
friend constexpr auto operator==(complex const &lhs, T const &rhs) -> bool
Definition complex.hpp:69
constexpr auto operator=(complex< X > const &other) -> complex< T > &
constexpr auto operator=(T const &val) -> complex< T > &
Definition complex.hpp:175
constexpr auto operator+=(T const &val) -> complex< T > &
Definition complex.hpp:183
constexpr auto real() const -> T
Definition complex.hpp:151
constexpr auto operator*=(T const &val) -> complex< T > &
Definition complex.hpp:197
constexpr complex(complex const &other)=default
constexpr auto operator=(complex const &other) -> complex &=default
T value_type
Definition complex.hpp:20
Definition integral_constant.hpp:9
T type
Definition complex.hpp:88
Provides compile-time indexed access to the type of the elements of the array using tuple-like interf...
Definition array.hpp:267
Definition tuple_size.hpp:15