4#ifndef TETL_COMPLEX_COMPLEX_HPP
5#define TETL_COMPLEX_COMPLEX_HPP
7#include <etl/_cstddef/size_t.hpp>
8#include <etl/_tuple/is_tuple_like.hpp>
9#include <etl/_tuple/tuple_element.hpp>
10#include <etl/_tuple/tuple_size.hpp>
11#include <etl/_type_traits/integral_constant.hpp>
12#include <etl/_utility/move.hpp>
23 constexpr complex(T
const& re = T(), T
const& im = T());
34 constexpr auto real(T val) ->
void;
37 constexpr auto imag(T val) ->
void;
53 template <size_t I,
typename X>
54 friend constexpr auto get(
complex<X>&)
noexcept -> X&;
56 template <size_t I,
typename X>
57 friend constexpr auto get(
complex<X>&&)
noexcept -> X&&;
59 template <size_t I,
typename X>
60 friend constexpr auto get(
complex<X>
const&)
noexcept -> X
const&;
62 template <size_t I,
typename X>
63 friend constexpr auto get(
complex<X>
const&&)
noexcept -> X
const&&;
67 return lhs.real() == rhs.real()
and lhs.imag() == rhs.imag();
72 return lhs.real() == rhs
and lhs.imag() == T{};
81inline constexpr auto is_tuple_like<etl::complex<T>> =
true;
86template <size_t I,
typename T>
88 static_assert(I < 2,
"Index out of range for etl::complex");
92template <size_t I,
typename X>
95 static_assert(I < 2,
"Index out of range for etl::complex");
96 if constexpr (I == 0) {
103template <size_t I,
typename X>
106 static_assert(I < 2,
"Index out of range for etl::complex");
107 if constexpr (I == 0) {
108 return etl::move(z._real);
110 return etl::move(z._imag);
114template <size_t I,
typename X>
117 static_assert(I < 2,
"Index out of range for etl::complex");
118 if constexpr (I == 0) {
125template <size_t I,
typename X>
126constexpr auto get(
complex<X>
const&& z)
noexcept -> X
const&&
128 static_assert(I < 2,
"Index out of range for etl::complex");
129 if constexpr (I == 0) {
130 return etl::move(z._real);
132 return etl::move(z._imag);
146 : _real{
static_cast<T>(other.real())}
147 , _imag{
static_cast<T>(other.imag())}
158constexpr auto complex<T>::real(T
const val) ->
void
170constexpr auto complex<T>::imag(T
const val) ->
void
233 auto const r =
static_cast<T>((_real * val.real()) - (_imag * val.imag()));
234 _imag =
static_cast<T>(_real * val.imag() + _imag * val.real());
243 auto const norm = [](
auto const& c) {
244 auto const x = c.real();
245 auto const y = c.imag();
246 return static_cast<T>(x * x + y * y);
249 auto const r =
static_cast<T>(_real * val.real() + _imag * val.imag());
250 auto const n = norm(val);
251 _imag = (_imag * val.real() - _real * val.imag()) / n;
265 return {
static_cast<T>(-val.real()),
static_cast<T>(-val.imag())};
346 return {0.0L
, static_cast<
long double>(d)
};
351 return {0.0L
, static_cast<
long double>(d)
};
356 return {0.0
, static_cast<
double>(d)
};
361 return {0.0
, static_cast<
double>(d)
};
366 return {0.0F
, static_cast<
float>(d)
};
371 return {0.0F
, static_cast<
float>(d)
};
Definition complex.hpp:342
constexpr auto operator""_i(unsigned long long d) -> complex< double >
Definition complex.hpp:359
constexpr auto operator""_il(unsigned long long d) -> complex< long double >
Definition complex.hpp:349
constexpr auto operator""_if(long double d) -> complex< float >
Definition complex.hpp:364
constexpr auto operator""_il(long double d) -> complex< long double >
Definition complex.hpp:344
constexpr auto operator""_if(unsigned long long d) -> complex< float >
Definition complex.hpp:369
constexpr auto operator""_i(long double d) -> complex< double >
Definition complex.hpp:354
Definition adjacent_find.hpp:9
constexpr auto get(complex< X > const &z) noexcept -> X const &
Definition complex.hpp:115
constexpr auto operator+(T const &lhs, complex< T > const &rhs) -> complex< T >
Definition complex.hpp:281
constexpr auto operator-(complex< T > const &lhs, complex< T > const &rhs) -> complex< T >
Definition complex.hpp:287
constexpr auto get(complex< X > &z) noexcept -> X &
Definition complex.hpp:93
constexpr auto operator+(complex< T > const &lhs, complex< T > const &rhs) -> complex< T >
Definition complex.hpp:269
constexpr auto operator-(complex< T > const &val) -> complex< T >
Definition complex.hpp:263
constexpr auto operator+(complex< T > const &val) -> complex< T >
Definition complex.hpp:257
constexpr auto operator/(T const &lhs, complex< T > const &rhs) -> complex< T >
Definition complex.hpp:335
constexpr auto get(complex< X > const &&z) noexcept -> X const &&
Definition complex.hpp:126
constexpr auto operator-(T const &lhs, complex< T > const &rhs) -> complex< T >
Definition complex.hpp:299
constexpr auto operator/(complex< T > const &lhs, T const &rhs) -> complex< T >
Definition complex.hpp:329
constexpr auto operator/(complex< T > const &lhs, complex< T > const &rhs) -> complex< T >
Definition complex.hpp:323
constexpr auto operator*(T const &lhs, complex< T > const &rhs) -> complex< T >
Definition complex.hpp:317
constexpr auto operator*(complex< T > const &lhs, complex< T > const &rhs) -> complex< T >
Definition complex.hpp:305
constexpr auto get(complex< X > &&z) noexcept -> X &&
Definition complex.hpp:104
constexpr auto operator-(complex< T > const &lhs, T const &rhs) -> complex< T >
Definition complex.hpp:293
constexpr auto operator*(complex< T > const &lhs, T const &rhs) -> complex< T >
Definition complex.hpp:311
constexpr auto operator+(complex< T > const &lhs, T const &rhs) -> complex< T >
Definition complex.hpp:275
A complex number.
Definition complex.hpp:20
explicit(sizeof(X) > sizeof(T)) const expr complex(complex< X > const &other)
constexpr auto operator+=(complex< X > const &val) -> complex< T > &
Definition complex.hpp:213
constexpr auto operator*=(complex< X > const &val) -> complex< T > &
Definition complex.hpp:231
constexpr auto imag(T val) -> void
Definition complex.hpp:170
constexpr auto operator/=(T const &val) -> complex< T > &
Definition complex.hpp:205
constexpr auto operator/=(complex< X > const &val) -> complex< T > &
Definition complex.hpp:241
constexpr auto operator-=(T const &val) -> complex< T > &
Definition complex.hpp:191
constexpr auto imag() const -> T
Definition complex.hpp:164
constexpr complex(T const &re=T(), T const &im=T())
Definition complex.hpp:137
friend constexpr auto get(complex< X > &&) noexcept -> X &&
Definition complex.hpp:104
constexpr auto real(T val) -> void
Definition complex.hpp:158
friend constexpr auto operator==(complex const &lhs, T const &rhs) -> bool
Definition complex.hpp:70
friend constexpr auto get(complex< X > &) noexcept -> X &
Definition complex.hpp:93
constexpr auto operator=(complex< X > const &other) -> complex< T > &
friend constexpr auto operator==(complex const &lhs, complex const &rhs) -> bool
Definition complex.hpp:65
constexpr auto operator=(T const &val) -> complex< T > &
Definition complex.hpp:176
constexpr auto operator+=(T const &val) -> complex< T > &
Definition complex.hpp:184
friend constexpr auto get(complex< X > const &) noexcept -> X const &
Definition complex.hpp:115
constexpr auto real() const -> T
Definition complex.hpp:152
constexpr auto operator*=(T const &val) -> complex< T > &
Definition complex.hpp:198
friend constexpr auto get(complex< X > const &&) noexcept -> X const &&
Definition complex.hpp:126
constexpr auto operator-=(complex< X > const &val) -> complex< T > &
Definition complex.hpp:222
constexpr complex(complex const &other)=default
constexpr auto operator=(complex const &other) -> complex &=default
Definition integral_constant.hpp:10