mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-28 01:59:59 +01:00
[poincare] Add a method isPositive on expressions
Change-Id: I3eb0064f8d64678326e74216517e0104eaa007fe
This commit is contained in:
@@ -11,6 +11,7 @@ class AbsoluteValue : public StaticHierarchy<1> {
|
||||
public:
|
||||
Type type() const override;
|
||||
Expression * clone() const override;
|
||||
bool isPositive() const override { return true; }
|
||||
private:
|
||||
template<typename T> static Complex<T> computeOnComplex(const Complex<T> c, AngleUnit angleUnit);
|
||||
virtual Evaluation<float> * privateEvaluate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -95,6 +95,9 @@ public:
|
||||
static Expression * parse(char const * string);
|
||||
virtual ~Expression() = default;
|
||||
virtual Expression * clone() const = 0;
|
||||
/* If isPositive is false, the expression has no sign (it does have to be
|
||||
* negative) */
|
||||
virtual bool isPositive() const { return false; }
|
||||
|
||||
/* Poor man's RTTI */
|
||||
virtual Type type() const = 0;
|
||||
|
||||
@@ -13,6 +13,7 @@ class Power : public StaticHierarchy<2> {
|
||||
public:
|
||||
Type type() const override;
|
||||
Expression * clone() const override;
|
||||
bool isPositive() const override;
|
||||
template<typename T> static Complex<T> compute(const Complex<T> c, const Complex<T> d);
|
||||
private:
|
||||
constexpr static float k_maxNumberOfSteps = 10000.0f;
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
// Expression subclassing
|
||||
Type type() const override;
|
||||
Expression * clone() const override;
|
||||
bool isPositive() const override { return !isNegative(); }
|
||||
|
||||
// Basic test
|
||||
bool isZero() const { return m_numerator.isZero(); }
|
||||
|
||||
@@ -23,6 +23,16 @@ Expression * Power::clone() const {
|
||||
return new Power(m_operands, true);
|
||||
}
|
||||
|
||||
bool Power::isPositive() const {
|
||||
if (operand(1)->type() == Type::Rational) {
|
||||
const Rational * r = static_cast<const Rational *>(operand(1));
|
||||
if (r->denominator().isOne() && Integer::Division(r->numerator(), Integer(2)).remainder.isZero()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Complex<T> Power::compute(const Complex<T> c, const Complex<T> d) {
|
||||
if (d.b() != 0) {
|
||||
|
||||
Reference in New Issue
Block a user