Skip to content

Commit

Permalink
Add Valuable conversion to rational
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhmm committed Jan 27, 2024
1 parent 053399d commit db48cba
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions omnn/math/Fraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ std::pair<bool,Valuable> Fraction::IsSummationSimplifiable(const Valuable& v) co
return static_cast<double>(numerator()) / static_cast<double>(denominator());
}

Fraction::operator a_rational() const
{
return static_cast<a_rational>(numerator()) / static_cast<a_rational>(denominator());
}

Valuable& Fraction::sq(){
numerator().sq();
denominator().sq();
Expand Down
1 change: 1 addition & 0 deletions omnn/math/Fraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ namespace math {

explicit operator unsigned char() const override;
explicit operator a_int() const override;
explicit operator a_rational() const override;
operator boost::multiprecision::cpp_dec_float_100() const;
Valuable operator()(const Variable&, const Valuable& augmentation) const override;
static max_exp_t getMaxVaExp(const Valuable& _1, const Valuable& _2) {
Expand Down
5 changes: 5 additions & 0 deletions omnn/math/Integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ namespace math {
return boost::numeric_cast<long double>(arbitrary);
}

Integer::operator a_rational() const
{
return boost::numeric_cast<a_rational>(arbitrary);
}

Integer::operator unsigned char() const
{
return boost::numeric_cast<unsigned char>(arbitrary);
Expand Down
1 change: 1 addition & 0 deletions omnn/math/Integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class Integer
explicit operator uint64_t() const override;
explicit operator double() const override;
explicit operator long double() const override;
explicit operator a_rational() const override;
explicit operator uint32_t() const override;
explicit operator unsigned char() const override;
a_int& a() override;
Expand Down
4 changes: 2 additions & 2 deletions omnn/math/Product.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ namespace math {
if (!e.IsInt()) {
IMPLEMENT
}
auto wasMax = maxVaExp == max_exp_t(e.ca(), 1);
auto wasMax = maxVaExp == static_cast<decltype(maxVaExp)>(e);
e += exponentiation;

auto isMax = maxVaExp < e.ca();
auto isMax = maxVaExp < static_cast<decltype(maxVaExp)>(e);
if (isMax) {
maxVaExp = e.ca();
}
Expand Down
8 changes: 8 additions & 0 deletions omnn/math/Valuable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,14 @@ bool Valuable::SerializedStrEqual(const std::string_view& s) const {
IMPLEMENT
}

Valuable::operator a_rational() const
{
if (exp)
return exp->operator a_rational();
else
IMPLEMENT
}

Valuable::operator uint32_t() const
{
if (exp)
Expand Down
1 change: 1 addition & 0 deletions omnn/math/Valuable.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ class Valuable
virtual explicit operator uint64_t() const;
virtual explicit operator double() const;
virtual explicit operator long double() const;
virtual explicit operator a_rational() const;
virtual explicit operator uint32_t() const;
virtual explicit operator unsigned char() const;
virtual a_int& a();
Expand Down

0 comments on commit db48cba

Please sign in to comment.