-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
41 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,38 @@ | ||
#include "fintamath/numbers/INumber.hpp" | ||
|
||
#include "fintamath/functions/arithmetic/Div.hpp" | ||
#include "fintamath/numbers/Integer.hpp" | ||
#include "fintamath/numbers/Rational.hpp" | ||
|
||
namespace fintamath { | ||
|
||
std::unique_ptr<IMathObject> Div::call(const ArgumentsRefVector &argsVect) const { | ||
return cast<IArithmetic>(argsVect.front().get()) / cast<IArithmetic>(argsVect.back().get()); | ||
static const auto multiPow = [] { | ||
static MultiMethod<std::unique_ptr<IMathObject>(const IArithmetic &, const IArithmetic &)> outMultiPow; | ||
|
||
outMultiPow.add<Integer, Integer>([](const Integer &lhs, const Integer &rhs) { | ||
return divSimpl(lhs, rhs); | ||
}); | ||
|
||
return outMultiPow; | ||
}(); | ||
|
||
const auto &lhs = cast<IArithmetic>(argsVect.front().get()); | ||
const auto &rhs = cast<IArithmetic>(argsVect.back().get()); | ||
|
||
if (auto res = multiPow(lhs, rhs)) { | ||
return res; | ||
} | ||
|
||
return lhs / rhs; | ||
} | ||
|
||
std::unique_ptr<IMathObject> Div::divSimpl(const Integer &lhs, const Integer &rhs) { | ||
if (lhs % rhs != 0) { | ||
return Rational(lhs, rhs).toMinimalObject(); | ||
} | ||
|
||
return (lhs / rhs).toMinimalObject(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters