17#ifndef MLIR_SUPPORT_COMPLEX_H
18#define MLIR_SUPPORT_COMPLEX_H
31template <
typename From,
typename To>
33 ->
decltype(
void(std::declval<To &>() = {std::declval<From &>()}),
36template <
typename,
typename>
39template <
typename From,
typename To>
42 decltype(detail::test_copy_list_initializable<From, To>(0))::value> {
45template <
typename From,
typename To>
67 std::enable_if_t<detail::is_copy_list_initializable_v<U, T>>...>
69 : re{other.re}, im{other.im} {}
72 std::enable_if_t<!detail::is_copy_list_initializable_v<U, T>>...>
74 : re(other.re), im(other.im) {}
77 std::enable_if_t<detail::is_copy_list_initializable_v<U, T>>...>
79 : re{other.
real()}, im{other.
imag()} {}
82 std::enable_if_t<!detail::is_copy_list_initializable_v<U, T>>...>
84 : re(other.
real()), im(other.
imag()) {}
86 [[nodiscard]]
constexpr T
real()
const {
return re; }
87 constexpr void real(T value) { re = value; }
88 [[nodiscard]]
constexpr T
imag()
const {
return im; }
89 constexpr void imag(T value) { im = value; }
143 template <
typename U>
151template <
typename T,
typename U>
152[[nodiscard]]
constexpr NonFloatComplex<T>
159template <
typename T,
typename U>
160[[nodiscard]]
constexpr NonFloatComplex<T>
168[[nodiscard]]
constexpr NonFloatComplex<T>
175 return {(a * c) - (
b * d), (a * d) + (
b * c)};
178template <
typename T,
typename U>
179[[nodiscard]]
constexpr NonFloatComplex<T>
187[[nodiscard]]
constexpr NonFloatComplex<T>
194 T denom = c * c + d * d;
195 return {(a * c +
b * d) / denom, (
b * c - a * d) / denom};
198template <
typename T,
typename U>
199[[nodiscard]]
constexpr NonFloatComplex<T>
207[[nodiscard]]
constexpr NonFloatComplex<T>
213[[nodiscard]]
constexpr NonFloatComplex<T>
224template <
typename T,
typename U>
230template <
typename T,
typename U>
242template <
typename T,
typename U>
248template <
typename T,
typename U>
265using Complex = std::conditional_t<std::is_floating_point_v<T>, std::complex<T>,
constexpr NonFloatComplex & operator-=(const T &real)
constexpr NonFloatComplex(const NonFloatComplex &other)=default
constexpr NonFloatComplex(const std::complex< U > &other)
constexpr NonFloatComplex & operator/=(const NonFloatComplex &other)
constexpr NonFloatComplex & operator+=(const NonFloatComplex &other)
constexpr NonFloatComplex & operator+=(const T &real)
constexpr NonFloatComplex & operator=(const NonFloatComplex &other)=default
constexpr NonFloatComplex & operator*=(const NonFloatComplex &other)
constexpr NonFloatComplex & operator/=(const T &real)
constexpr NonFloatComplex & operator=(const T &real)
constexpr NonFloatComplex(const T &re=T{}, const T &im=T{})
constexpr NonFloatComplex & operator*=(const T &real)
constexpr NonFloatComplex(const NonFloatComplex< U > &other)
constexpr NonFloatComplex & operator=(const std::complex< U > &other)
constexpr void real(T value)
constexpr NonFloatComplex & operator-=(const NonFloatComplex &other)
constexpr void imag(T value)
auto test_copy_list_initializable(int) -> decltype(void(std::declval< To & >()={std::declval< From & >()}), std::true_type{})
constexpr bool is_copy_list_initializable_v
Include the generated interface declarations.
constexpr T real(const NonFloatComplex< T > &x)
bool operator==(StringAttr lhs, std::nullptr_t)
Define comparisons for StringAttr against nullptr and itself to avoid the StringRef overloads from be...
bool operator!=(RegionBranchPoint lhs, RegionBranchPoint rhs)
constexpr NonFloatComplex< T > operator/(const NonFloatComplex< T > &x, const NonFloatComplex< T > &y)
AffineExpr operator-(int64_t val, AffineExpr expr)
std::conditional_t< std::is_floating_point_v< T >, std::complex< T >, NonFloatComplex< T > > Complex
AffineExpr operator+(int64_t val, AffineExpr expr)
AffineExpr operator*(int64_t val, AffineExpr expr)
constexpr T imag(const NonFloatComplex< T > &x)