mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Add NullStatus for expressions
Change-Id: Ibaba72e3e3589ba259c7b22d402e2b27937f27c1
This commit is contained in:
committed by
Émilie Feral
parent
b2945c3f8b
commit
4a3f749cc6
@@ -28,7 +28,7 @@ public:
|
||||
// Expression subclassing
|
||||
Type type() const override { return Type::BasedInteger; }
|
||||
Sign sign(Context * context) const override { return Sign::Positive; }
|
||||
bool isNumberZero() const override { return integer().isZero(); }
|
||||
NullStatus nullStatus(Context * context) const override { return integer().isZero() ? NullStatus::Null : NullStatus::NonNull; }
|
||||
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
// Expression Properties
|
||||
Type type() const override { return Type::Constant; }
|
||||
Sign sign(Context * context) const override;
|
||||
NullStatus nullStatus(Context * context) const override { return NullStatus::NonNull; }
|
||||
|
||||
/* Layout */
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -42,8 +42,8 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::Decimal; }
|
||||
Sign sign(Context * context) const override { return m_negative ? Sign::Negative : Sign::Positive; }
|
||||
NullStatus nullStatus(Context * context) const override { return unsignedMantissa().isZero() ? NullStatus::Null : NullStatus::NonNull; }
|
||||
Expression setSign(Sign s, ReductionContext reductionContext) override;
|
||||
bool isNumberZero() const override { return unsignedMantissa().isZero(); }
|
||||
|
||||
// Approximation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -151,9 +151,10 @@ public:
|
||||
ExpressionNode::Type type() const { return node()->type(); }
|
||||
bool isOfType(ExpressionNode::Type * types, int length) const { return node()->isOfType(types, length); }
|
||||
ExpressionNode::Sign sign(Context * context) const { return node()->sign(context); }
|
||||
ExpressionNode::NullStatus nullStatus(Context * context) const { return node()->nullStatus(context); }
|
||||
bool isStrictly(ExpressionNode::Sign s, Context * context) const { return s == node()->sign(context) && node()->nullStatus(context) == ExpressionNode::NullStatus::NonNull; }
|
||||
bool isUndefined() const { return node()->type() == ExpressionNode::Type::Undefined || node()->type() == ExpressionNode::Type::Unreal; }
|
||||
bool isNumber() const { return node()->isNumber(); }
|
||||
bool isNumberZero() const { return node()->isNumberZero(); }
|
||||
bool isRationalOne() const;
|
||||
bool isRandom() const { return node()->isRandom(); }
|
||||
bool isParameteredExpression() const { return node()->isParameteredExpression(); }
|
||||
|
||||
@@ -156,6 +156,11 @@ public:
|
||||
Unknown = 0,
|
||||
Positive = 1
|
||||
};
|
||||
enum class NullStatus {
|
||||
Unknown = -1,
|
||||
NonNull = 0,
|
||||
Null = 1,
|
||||
};
|
||||
|
||||
class ReductionContext {
|
||||
public:
|
||||
@@ -186,8 +191,8 @@ public:
|
||||
};
|
||||
|
||||
virtual Sign sign(Context * context) const { return Sign::Unknown; }
|
||||
virtual NullStatus nullStatus(Context * context) const { return NullStatus::Unknown; }
|
||||
virtual bool isNumber() const { return false; }
|
||||
virtual bool isNumberZero() const { return false; }
|
||||
virtual bool isRandom() const { return false; }
|
||||
virtual bool isParameteredExpression() const { return false; }
|
||||
/* childAtIndexNeedsUserParentheses checks if parentheses are required by mathematical rules:
|
||||
|
||||
@@ -38,9 +38,9 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return (sizeof(T) == sizeof(float)) ? Type::Float : Type::Double; }
|
||||
Sign sign(Context * context) const override { return m_value < 0 ? Sign::Negative : Sign::Positive; }
|
||||
NullStatus nullStatus(Context * context) const override { return m_value == 0.0 ? NullStatus::Null : NullStatus::NonNull; }
|
||||
Expression setSign(Sign s, ReductionContext reductionContext) override;
|
||||
int simplificationOrderSameType(const ExpressionNode * e, bool ascending, bool canBeInterrupted, bool ignoreParentheses) const override;
|
||||
bool isNumberZero() const override { return m_value == 0.0; }
|
||||
|
||||
// Layout
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
Type type() const override { return Type::HyperbolicArcCosine; }
|
||||
private:
|
||||
// Simplification
|
||||
bool isNotableValue(Expression e) const override { return e.isRationalOne(); }
|
||||
bool isNotableValue(Expression e, Context * context) const override { return e.isRationalOne(); }
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -17,7 +17,7 @@ private:
|
||||
LayoutShape leftLayoutShape() const override { return LayoutShape::MoreLetters; };
|
||||
LayoutShape rightLayoutShape() const override { return LayoutShape::BoundaryPunctuation; }
|
||||
Expression shallowReduce(ReductionContext reductionContext) override;
|
||||
virtual bool isNotableValue(Expression e) const { return e.isNumberZero(); }
|
||||
virtual bool isNotableValue(Expression e, Context * context) const { return e.nullStatus(context) == ExpressionNode::NullStatus::Null; }
|
||||
virtual Expression imageOfNotableValue() const { return Rational::Builder(0); }
|
||||
};
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::Infinity; }
|
||||
Sign sign(Context * context) const override { return m_negative ? Sign::Negative : Sign::Positive; }
|
||||
NullStatus nullStatus(Context * context) const override { return NullStatus::NonNull; }
|
||||
Expression setSign(Sign s, ReductionContext reductionContext) override;
|
||||
|
||||
// Approximation
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
bool isNegative() const { return m_negative; }
|
||||
void setNegative(bool negative) { m_negative = negative; }
|
||||
bool isInteger() const { return denominator().isOne(); }
|
||||
bool isNumberZero() const override { return isZero(); }
|
||||
NullStatus nullStatus(Context * context) const override { return isZero() ? NullStatus::Null : NullStatus::NonNull; }
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override;
|
||||
|
||||
Reference in New Issue
Block a user