mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:17:35 +00:00
AK: Fix bugs in Complex += -= + - * / operators
There were two issues: 1) the C+=R and C-=R operators expected arithmetic types to have .real() 2) the R+C, R-C, R*C and R/C operators applied the operation in wrong order (did C+R, C-R, C*R and C/R instead). This wouldn't matter for + and * which are commutative, but is incorrect for - and /.
This commit is contained in:
parent
963a6b3d3d
commit
58d0577a02
2 changed files with 32 additions and 6 deletions
12
AK/Complex.h
12
AK/Complex.h
|
@ -83,7 +83,7 @@ public:
|
|||
template<AK::Concepts::Arithmetic U>
|
||||
constexpr Complex<T> operator+=(U const& x)
|
||||
{
|
||||
m_real += x.real();
|
||||
m_real += x;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ public:
|
|||
template<AK::Concepts::Arithmetic U>
|
||||
constexpr Complex<T> operator-=(U const& x)
|
||||
{
|
||||
m_real -= x.real();
|
||||
m_real -= x;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -224,7 +224,7 @@ private:
|
|||
|
||||
// reverse associativity operators for scalars
|
||||
template<AK::Concepts::Arithmetic T, AK::Concepts::Arithmetic U>
|
||||
constexpr Complex<T> operator+(U const& b, Complex<T> const& a)
|
||||
constexpr Complex<T> operator+(U const& a, Complex<T> const& b)
|
||||
{
|
||||
Complex<T> x = a;
|
||||
x += b;
|
||||
|
@ -232,7 +232,7 @@ constexpr Complex<T> operator+(U const& b, Complex<T> const& a)
|
|||
}
|
||||
|
||||
template<AK::Concepts::Arithmetic T, AK::Concepts::Arithmetic U>
|
||||
constexpr Complex<T> operator-(U const& b, Complex<T> const& a)
|
||||
constexpr Complex<T> operator-(U const& a, Complex<T> const& b)
|
||||
{
|
||||
Complex<T> x = a;
|
||||
x -= b;
|
||||
|
@ -240,7 +240,7 @@ constexpr Complex<T> operator-(U const& b, Complex<T> const& a)
|
|||
}
|
||||
|
||||
template<AK::Concepts::Arithmetic T, AK::Concepts::Arithmetic U>
|
||||
constexpr Complex<T> operator*(U const& b, Complex<T> const& a)
|
||||
constexpr Complex<T> operator*(U const& a, Complex<T> const& b)
|
||||
{
|
||||
Complex<T> x = a;
|
||||
x *= b;
|
||||
|
@ -248,7 +248,7 @@ constexpr Complex<T> operator*(U const& b, Complex<T> const& a)
|
|||
}
|
||||
|
||||
template<AK::Concepts::Arithmetic T, AK::Concepts::Arithmetic U>
|
||||
constexpr Complex<T> operator/(U const& b, Complex<T> const& a)
|
||||
constexpr Complex<T> operator/(U const& a, Complex<T> const& b)
|
||||
{
|
||||
Complex<T> x = a;
|
||||
x /= b;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue