-
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
15 changed files
with
557 additions
and
0 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 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "fintamath/functions/IFunction.hpp" | ||
#include "fintamath/numbers/INumber.hpp" | ||
|
||
namespace fintamath { | ||
|
||
class Ceil : public IFunctionCRTP<INumber, Ceil, INumber> { | ||
public: | ||
Ceil() = default; | ||
|
||
std::string toString() const override { | ||
return "ceil"; | ||
} | ||
|
||
static MathObjectType getTypeStatic() { | ||
return MathObjectType::Ceil; | ||
} | ||
|
||
protected: | ||
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argsVect) const override; | ||
|
||
private: | ||
static std::unique_ptr<IMathObject> multiCeilSimplify(const INumber &rhs); | ||
}; | ||
|
||
FINTAMATH_FUNCTION_EXPRESSION(Ceil, ceilExpr); | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "fintamath/functions/IFunction.hpp" | ||
#include "fintamath/numbers/INumber.hpp" | ||
|
||
namespace fintamath { | ||
|
||
class Floor : public IFunctionCRTP<INumber, Floor, INumber> { | ||
public: | ||
Floor() = default; | ||
|
||
std::string toString() const override { | ||
return "floor"; | ||
} | ||
|
||
static MathObjectType getTypeStatic() { | ||
return MathObjectType::Floor; | ||
} | ||
|
||
protected: | ||
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argsVect) const override; | ||
|
||
private: | ||
static std::unique_ptr<IMathObject> multiFloorSimplify(const INumber &rhs); | ||
}; | ||
|
||
FINTAMATH_FUNCTION_EXPRESSION(Floor, floorExpr); | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "fintamath/functions/IOperator.hpp" | ||
#include "fintamath/numbers/INumber.hpp" | ||
#include "fintamath/numbers/Integer.hpp" | ||
|
||
namespace fintamath { | ||
|
||
class Mod : public IOperatorCRTP<INumber, Mod, INumber, INumber> { | ||
public: | ||
Mod() : IOperatorCRTP(IOperator::Priority::Modulo) { | ||
} | ||
|
||
std::string toString() const override { | ||
return "mod"; | ||
} | ||
|
||
static MathObjectType getTypeStatic() { | ||
return MathObjectType::Mod; | ||
} | ||
|
||
protected: | ||
std::unique_ptr<IMathObject> call(const ArgumentRefVector &argsVect) const override; | ||
|
||
private: | ||
static std::unique_ptr<IMathObject> multiModSimplify(const INumber &lhs, const INumber &rhs); | ||
}; | ||
|
||
FINTAMATH_FUNCTION_EXPRESSION(Mod, modExpr); | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "fintamath/functions/ntheory/Ceil.hpp" | ||
|
||
#include "fintamath/functions/powers/Sqrt.hpp" | ||
#include "fintamath/numbers/Complex.hpp" | ||
#include "fintamath/numbers/Integer.hpp" | ||
#include "fintamath/numbers/IntegerFunctions.hpp" | ||
#include "fintamath/numbers/Rational.hpp" | ||
#include "fintamath/numbers/RationalFunctions.hpp" | ||
#include "fintamath/numbers/Real.hpp" | ||
#include "fintamath/numbers/RealFunctions.hpp" | ||
|
||
namespace fintamath { | ||
|
||
std::unique_ptr<IMathObject> Ceil::call(const ArgumentRefVector &argsVect) const { | ||
const auto &rhs = cast<INumber>(argsVect.front().get()); | ||
|
||
return multiCeilSimplify(rhs); | ||
} | ||
|
||
std::unique_ptr<IMathObject> Ceil::multiCeilSimplify(const INumber &rhs) { | ||
static const auto multiCeil = [] { | ||
static MultiMethod<std::unique_ptr<IMathObject>(const INumber &)> outMultiCeil; | ||
|
||
outMultiCeil.add<Integer>([](const Integer &inRhs) { | ||
return inRhs.clone(); | ||
}); | ||
|
||
outMultiCeil.add<Rational>([](const Rational &inRhs) { | ||
return ceil(inRhs).clone(); | ||
}); | ||
|
||
outMultiCeil.add<Real>([](const Real &inRhs) { | ||
return ceil(inRhs).clone(); | ||
}); | ||
|
||
outMultiCeil.add<Complex>([](const Complex &inRhs) { | ||
const auto re = cast<INumber>(multiCeilSimplify(inRhs.real())); | ||
const auto im = cast<INumber>(multiCeilSimplify(inRhs.imag())); | ||
return Complex(*re, *im).toMinimalObject(); | ||
}); | ||
|
||
return outMultiCeil; | ||
}(); | ||
|
||
return multiCeil(rhs); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "fintamath/functions/ntheory/Floor.hpp" | ||
|
||
#include "fintamath/functions/powers/Sqrt.hpp" | ||
#include "fintamath/numbers/Complex.hpp" | ||
#include "fintamath/numbers/Integer.hpp" | ||
#include "fintamath/numbers/IntegerFunctions.hpp" | ||
#include "fintamath/numbers/Rational.hpp" | ||
#include "fintamath/numbers/RationalFunctions.hpp" | ||
#include "fintamath/numbers/Real.hpp" | ||
#include "fintamath/numbers/RealFunctions.hpp" | ||
|
||
namespace fintamath { | ||
|
||
std::unique_ptr<IMathObject> Floor::call(const ArgumentRefVector &argsVect) const { | ||
const auto &rhs = cast<INumber>(argsVect.front().get()); | ||
|
||
return multiFloorSimplify(rhs); | ||
} | ||
|
||
std::unique_ptr<IMathObject> Floor::multiFloorSimplify(const INumber &rhs) { | ||
static const auto multiFloor = [] { | ||
static MultiMethod<std::unique_ptr<IMathObject>(const INumber &)> outMultiFloor; | ||
|
||
outMultiFloor.add<Integer>([](const Integer &inRhs) { | ||
return inRhs.clone(); | ||
}); | ||
|
||
outMultiFloor.add<Rational>([](const Rational &inRhs) { | ||
return floor(inRhs).clone(); | ||
}); | ||
|
||
outMultiFloor.add<Real>([](const Real &inRhs) { | ||
return floor(inRhs).clone(); | ||
}); | ||
|
||
outMultiFloor.add<Complex>([](const Complex &inRhs) { | ||
const auto re = cast<INumber>(multiFloorSimplify(inRhs.real())); | ||
const auto im = cast<INumber>(multiFloorSimplify(inRhs.imag())); | ||
return Complex(*re, *im).toMinimalObject(); | ||
}); | ||
|
||
return outMultiFloor; | ||
}(); | ||
|
||
return multiFloor(rhs); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "fintamath/functions/ntheory/Mod.hpp" | ||
|
||
#include "fintamath/literals/constants/Undefined.hpp" | ||
#include "fintamath/numbers/IntegerFunctions.hpp" | ||
|
||
namespace fintamath { | ||
|
||
std::unique_ptr<IMathObject> Mod::call(const ArgumentRefVector &argsVect) const { | ||
const auto &lhs = cast<INumber>(argsVect.front().get()); | ||
const auto &rhs = cast<INumber>(argsVect.back().get()); | ||
|
||
if (rhs == Integer(0)) { | ||
return Undefined().clone(); | ||
} | ||
|
||
return multiModSimplify(lhs, rhs); | ||
} | ||
|
||
std::unique_ptr<IMathObject> Mod::multiModSimplify(const INumber &lhs, const INumber &rhs) { | ||
// TODO: implement non-integer modulo | ||
|
||
static const auto multiMod = [] { | ||
static MultiMethod<std::unique_ptr<IMathObject>(const INumber &, const INumber &)> outMultiMod; | ||
|
||
outMultiMod.add<Integer, Integer>([](const Integer &inLhs, const Integer &inRhs) { | ||
if (inLhs == 0 || abs(inRhs) == 1) { | ||
return Integer(0).clone(); | ||
} | ||
|
||
Integer mod = inLhs % inRhs; | ||
|
||
if (inLhs.sign() != inRhs.sign()) { | ||
mod += inRhs; | ||
} | ||
|
||
return std::move(mod).clone(); | ||
}); | ||
|
||
return outMultiMod; | ||
}(); | ||
|
||
return multiMod(lhs, rhs); | ||
} | ||
|
||
} |
Oops, something went wrong.