erigon-pulse/erigon-lib/pedersen_hash/fraction_field_element.inl
battlmonstr 231e468e19 Add 'erigon-lib/' from commit '93d9c9d9fe4bd8a49f7a98a6bce0f0da7094c7d3'
git-subtree-dir: erigon-lib
git-subtree-mainline: 3c8cbda809
git-subtree-split: 93d9c9d9fe
2023-09-20 14:50:25 +02:00

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