18 inline namespace _V1 {
22 namespace experimental {
25 class complex<_Tp, typename
std::enable_if_t<is_genfloat<_Tp>::value>> {
36 : __re_(__re), __im_(__im) {}
38 template <
typename _Xp>
40 : __re_(__c.
real()), __im_(__c.
imag()) {}
42 template <class _Xp, typename = std::enable_if_t<is_genfloat<_Xp>::value>>
44 const std::complex<_Xp> &__c)
48 template <class _Xp, typename = std::enable_if_t<is_genfloat<_Xp>::value>>
50 operator std::complex<_Xp>()
const {
51 return std::complex<_Xp>(
static_cast<_Xp
>(__re_),
static_cast<_Xp
>(__im_));
101 __x.__re_ += __y.real();
102 __x.__im_ += __y.imag();
108 __x.__re_ -= __y.real();
109 __x.__im_ -= __y.imag();
115 __x = __x *
complex(__y.real(), __y.imag());
121 __x = __x /
complex(__y.real(), __y.imag());
184 bool __recalc =
false;
185 if (sycl::isinf(__a) || sycl::isinf(__b)) {
196 if (sycl::isinf(__c) || sycl::isinf(__d)) {
207 if (!__recalc && (sycl::isinf(__ac) || sycl::isinf(__bd) ||
208 sycl::isinf(__ad) || sycl::isinf(__bc))) {
220 __x =
value_type(INFINITY) * (__a * __c - __b * __d);
221 __y =
value_type(INFINITY) * (__a * __d + __b * __c);
248 if (sycl::isfinite(__logbw)) {
249 __ilogbw =
static_cast<int>(__logbw);
250 __c = sycl::ldexp(__c, -__ilogbw);
251 __d = sycl::ldexp(__d, -__ilogbw);
254 value_type __x = sycl::ldexp((__a * __c + __b * __d) / __denom, -__ilogbw);
255 value_type __y = sycl::ldexp((__b * __c - __a * __d) / __denom, -__ilogbw);
261 }
else if ((sycl::isinf(__a) || sycl::isinf(__b)) &&
262 sycl::isfinite(__c) && sycl::isfinite(__d)) {
267 __x =
value_type(INFINITY) * (__a * __c + __b * __d);
268 __y =
value_type(INFINITY) * (__b * __c - __a * __d);
269 }
else if (sycl::isinf(__logbw) && __logbw >
value_type(0) &&
270 sycl::isfinite(__a) && sycl::isfinite(__b)) {
275 __x =
value_type(0) * (__a * __c + __b * __d);
276 __y =
value_type(0) * (__b * __c - __a * __d);
294 return __x.__re_ == __y.__re_ && __x.__im_ == __y.__im_;
298 return __x.__re_ == __y && __x.__im_ == 0;
302 return __x == __y.__re_ && 0 == __y.__im_;
307 return !(__x == __y);
311 return !(__x == __y);
315 return !(__x == __y);
318 template <
class _CharT,
class _Traits>
324 if (__is.peek() == _CharT(
'(')) {
330 _CharT __c = __is.peek();
331 if (__c == _CharT(
',')) {
338 if (__c == _CharT(
')')) {
342 __is.setstate(__is.failbit);
344 __is.setstate(__is.failbit);
345 }
else if (__c == _CharT(
')')) {
349 __is.setstate(__is.failbit);
351 __is.setstate(__is.failbit);
358 __is.setstate(__is.failbit);
361 __is.setstate(__is.failbit);
365 template <
class _CharT,
class _Traits>
367 operator<<(std::basic_ostream<_CharT, _Traits> &__os,
369 std::basic_ostringstream<_CharT, _Traits> __s;
370 __s.flags(__os.flags());
371 __s.imbue(__os.getloc());
372 __s.precision(__os.precision());
373 __s <<
'(' << __x.__re_ <<
',' << __x.__im_ <<
')';
374 return __os << __s.str();
379 return __ss <<
"(" << _x.__re_ <<
"," << _x.__im_ <<
")";
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator*(value_type __x, const complex< value_type > &__y)
constexpr _SYCL_EXT_CPLX_INLINE_VISIBILITY value_type real() const
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex & operator+=(complex< value_type > &__c, value_type __re)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex & operator*=(complex< value_type > &__x, const complex< _Xp > &__y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY constexpr friend bool operator==(const complex< value_type > &__x, const complex< value_type > &__y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator*(const complex< value_type > &__z, const complex< value_type > &__w)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator-(const complex< value_type > &__x)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex & operator/=(complex< value_type > &__x, const complex< _Xp > &__y)
constexpr _SYCL_EXT_CPLX_INLINE_VISIBILITY complex(value_type __re=value_type(), value_type __im=value_type())
_SYCL_EXT_CPLX_INLINE_VISIBILITY constexpr friend bool operator==(const complex< value_type > &__x, value_type __y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY complex & operator=(const complex< _Xp > &__c)
constexpr _SYCL_EXT_CPLX_INLINE_VISIBILITY value_type imag() const
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex & operator*=(complex< value_type > &__c, value_type __re)
_SYCL_EXT_CPLX_INLINE_VISIBILITY constexpr friend bool operator!=(value_type __x, const complex< value_type > &__y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator/(value_type __x, const complex< value_type > &__y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator+(const complex< value_type > &__x, value_type __y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator*(const complex< value_type > &__x, value_type __y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex & operator+=(complex< value_type > &__x, const complex< _Xp > &__y)
constexpr _SYCL_EXT_CPLX_INLINE_VISIBILITY complex(const std::complex< _Xp > &__c)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator-(const complex< value_type > &__x, const complex< value_type > &__y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator/(const complex< value_type > &__z, const complex< value_type > &__w)
_SYCL_EXT_CPLX_INLINE_VISIBILITY void real(value_type __re)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex & operator-=(complex< value_type > &__x, const complex< _Xp > &__y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator/(const complex< value_type > &__x, value_type __y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator+(const complex< value_type > &__x)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator-(value_type __x, const complex< value_type > &__y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator+(const complex< value_type > &__x, const complex< value_type > &__y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY constexpr friend bool operator!=(const complex< value_type > &__x, value_type __y)
constexpr _SYCL_EXT_CPLX_INLINE_VISIBILITY complex(const complex< _Xp > &__c)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator+(value_type __x, const complex< value_type > &__y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY complex & operator=(value_type __re)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, complex< value_type > &__x)
_SYCL_EXT_CPLX_INLINE_VISIBILITY constexpr friend bool operator!=(const complex< value_type > &__x, const complex< value_type > &__y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex< value_type > operator-(const complex< value_type > &__x, value_type __y)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex & operator/=(complex< value_type > &__c, value_type __re)
_SYCL_EXT_CPLX_INLINE_VISIBILITY void imag(value_type __im)
_SYCL_EXT_CPLX_INLINE_VISIBILITY friend complex & operator-=(complex< value_type > &__c, value_type __re)
_SYCL_EXT_CPLX_INLINE_VISIBILITY constexpr friend bool operator==(value_type __x, const complex< value_type > &__y)
#define _SYCL_EXT_CPLX_INLINE_VISIBILITY
DEFINES.
std::enable_if_t< std::is_same_v< Tp, float >, float > copysign(Tp x, Tp y)
__DPCPP_SYCL_EXTERNAL constexpr _SYCL_EXT_CPLX_INLINE_VISIBILITY std::enable_if_t< is_genfloat< _Tp >::value, _Tp > real(const complex< _Tp > &__c)
std::enable_if_t< std::is_same_v< T, bfloat16 >, bool > isnan(T x)
__DPCPP_SYCL_EXTERNAL constexpr _SYCL_EXT_CPLX_INLINE_VISIBILITY std::enable_if_t< is_genfloat< _Tp >::value, _Tp > imag(const complex< _Tp > &__c)
std::enable_if_t< detail::is_bf16_storage_type< T >::value, T > fabs(T x)
std::ostream & operator<<(std::ostream &Out, backend be)