mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
231e468e19
git-subtree-dir: erigon-lib git-subtree-mainline:3c8cbda809
git-subtree-split:93d9c9d9fe
43 lines
1.7 KiB
C++
43 lines
1.7 KiB
C++
#include "fraction_field_element.h"
|
|
|
|
#include "error_handling.h"
|
|
|
|
namespace starkware {
|
|
|
|
template <typename FieldElementT>
|
|
FractionFieldElement<FieldElementT> FractionFieldElement<FieldElementT>::operator+(
|
|
const FractionFieldElement<FieldElementT>& rhs) const {
|
|
const auto num_value = this->numerator_ * rhs.denominator_ + this->denominator_ * rhs.numerator_;
|
|
const auto denom_value = this->denominator_ * rhs.denominator_;
|
|
return FractionFieldElement(num_value, denom_value);
|
|
}
|
|
|
|
template <typename FieldElementT>
|
|
FractionFieldElement<FieldElementT> FractionFieldElement<FieldElementT>::operator-(
|
|
const FractionFieldElement<FieldElementT>& rhs) const {
|
|
const auto num_value = this->numerator_ * rhs.denominator_ - this->denominator_ * rhs.numerator_;
|
|
const auto denom_value = this->denominator_ * rhs.denominator_;
|
|
return FractionFieldElement(num_value, denom_value);
|
|
}
|
|
|
|
template <typename FieldElementT>
|
|
FractionFieldElement<FieldElementT> FractionFieldElement<FieldElementT>::operator*(
|
|
const FractionFieldElement<FieldElementT>& rhs) const {
|
|
return FractionFieldElement(
|
|
this->numerator_ * rhs.numerator_, this->denominator_ * rhs.denominator_);
|
|
}
|
|
|
|
template <typename FieldElementT>
|
|
bool FractionFieldElement<FieldElementT>::operator==(
|
|
const FractionFieldElement<FieldElementT>& rhs) const {
|
|
return this->numerator_ * rhs.denominator_ == this->denominator_ * rhs.numerator_;
|
|
}
|
|
|
|
template <typename FieldElementT>
|
|
FractionFieldElement<FieldElementT> FractionFieldElement<FieldElementT>::Inverse() const {
|
|
ASSERT(this->numerator_ != FieldElementT::Zero(), "Zero does not have an inverse");
|
|
return FractionFieldElement(denominator_, numerator_);
|
|
}
|
|
|
|
} // namespace starkware
|