Skip to content

Commit

Permalink
Dennis' remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcou committed May 14, 2022
1 parent 835cc03 commit ff338b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
23 changes: 13 additions & 10 deletions include/eve/module/complex/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace eve
//!
//! **Required header:** `#include <eve/module/complex.hpp>`
//!
//! eve::complex is structure representing complex number and mean to be used in conjunction with
//! eve::wide.
//! eve::complex is structure representing complex number and is meant to be used in
//! conjunction with eve::wide.
//!
//! @tparam Type Underlying floating point type
//================================================================================================
Expand All @@ -49,7 +49,10 @@ namespace eve
/// Stream insertion operator
friend std::ostream& operator<<(std::ostream& os, like<complex> auto const& z)
{
return os << real(z) << std::showpos << imag(z) << "i" << std::noshowpos;
os << real(z);
auto i = imag(z);
if(i >= 0) os << '+' << i; else os << '-' << -i;
return os << 'i';
}

//==============================================================================================
Expand Down Expand Up @@ -120,18 +123,18 @@ namespace eve
}

template<like<complex> Z1, real_value Z2>
EVE_FORCEINLINE friend auto operator+(Z1 const& lhs, Z2 const& rhs) noexcept
requires(requires(as_wide_as_t<Z1,Z2> t) { t += rhs; })
EVE_FORCEINLINE friend auto operator+(Z1 const& x, Z2 const& y) noexcept
requires(requires(as_wide_as_t<Z1,Z2> t) { t += y; })
{
as_wide_as_t<Z1,Z2> that{lhs};
return that += rhs;
as_wide_as_t<Z1,Z2> that{x};
return that += y;
}

template<real_value Z1, like<complex> Z2>
EVE_FORCEINLINE friend auto operator+(Z1 const& lhs, Z2 const& rhs) noexcept
requires(requires(as_wide_as_t<Z2,Z1> t) { t += lhs; })
EVE_FORCEINLINE friend auto operator+(Z1 const& x, Z2 const& y) noexcept
requires(requires(as_wide_as_t<Z2,Z1> t) { t += x; })
{
return rhs + lhs;
return y + x;
}

//==============================================================================================
Expand Down
12 changes: 2 additions & 10 deletions include/eve/product_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,8 @@ namespace eve
template<like<Self> Z1, like<Self> Z2>
EVE_FORCEINLINE friend auto operator+(Z1 x, Z2 y) requires requires { x += x; }
{
if constexpr(scalar_value<Z1> && simd_value<Z2>)
{
as_wide_t<Z1> that{x};
return that += y;
}
else
{
x += y;
return x;
}
if constexpr(scalar_value<Z1> && simd_value<Z2>) return y += x;
else return x += y;
}

EVE_FORCEINLINE friend auto operator-(eve::like<Self> auto x, eve::like<Self> auto y) requires requires { x -= y; }
Expand Down

0 comments on commit ff338b5

Please sign in to comment.