[ARITHMETIC OPERATORS][IMPLEMENTATION] implmeented the binary, unary and compound - operator

This commit is contained in:
kallore 2025-05-19 10:24:49 +02:00
parent ec63380746
commit 12b867e1c9
3 changed files with 33 additions and 0 deletions

View file

@ -43,6 +43,8 @@ namespace rotgen
double const& operator()(std::size_t index) const; double const& operator()(std::size_t index) const;
matrix_impl64& operator+=(matrix_impl64 const& rhs); matrix_impl64& operator+=(matrix_impl64 const& rhs);
matrix_impl64& operator-=(matrix_impl64 const& rhs);
matrix_impl64& operator-();
matrix_impl64& operator*=(matrix_impl64 const& rhs); matrix_impl64& operator*=(matrix_impl64 const& rhs);
matrix_impl64& operator*=(double d); matrix_impl64& operator*=(double d);

View file

@ -69,6 +69,17 @@ namespace rotgen
return *this; return *this;
} }
matrix& operator-=(matrix const& rhs)
{
static_cast<parent&>(*this) -= static_cast<parent const&>(rhs);
return *this;
}
matrix& operator-()
{
return static_cast<parent const&>(*this).operator-();
}
matrix& operator*=(matrix const& rhs) matrix& operator*=(matrix const& rhs)
{ {
static_cast<parent&>(*this) *= static_cast<parent const&>(rhs); static_cast<parent&>(*this) *= static_cast<parent const&>(rhs);
@ -89,6 +100,13 @@ namespace rotgen
return that += rhs; return that += rhs;
} }
template<typename S, int R, int C, int O, int MR, int MC>
matrix<S,R,C,O,MR,MC> operator-(matrix<S,R,C,O,MR,MC> const& lhs, matrix<S,R,C,O,MR,MC> const& rhs)
{
matrix<S,R,C,O,MR,MC> that(lhs);
return that -= rhs;
}
template<typename S, int R, int C, int O, int MR, int MC> template<typename S, int R, int C, int O, int MR, int MC>
matrix<S,R,C,O,MR,MC> operator*(matrix<S,R,C,O,MR,MC> const& lhs, matrix<S,R,C,O,MR,MC> const& rhs) matrix<S,R,C,O,MR,MC> operator*(matrix<S,R,C,O,MR,MC> const& lhs, matrix<S,R,C,O,MR,MC> const& rhs)
{ {

View file

@ -95,6 +95,19 @@ namespace rotgen
return *this; return *this;
} }
matrix_impl64& matrix_impl64::operator-=(matrix_impl64 const& rhs)
{
storage_->data -= rhs.storage_->data;
return *this;
}
matrix_impl64& matrix_impl64::operator-()
{
matrix_impl64 result(*this);
result.storage_->data = -result.storage_->data;
return result;
}
matrix_impl64& matrix_impl64::operator*=(matrix_impl64 const& rhs) matrix_impl64& matrix_impl64::operator*=(matrix_impl64 const& rhs)
{ {
storage_->data *= rhs.storage_->data; storage_->data *= rhs.storage_->data;