[apps/calculation] Calculation: add a methods additionalOuput

This commit is contained in:
Émilie Feral
2019-10-15 17:17:40 +02:00
committed by Léa Saviot
parent 29c50702ae
commit fa5902dcd2
3 changed files with 37 additions and 3 deletions

View File

@@ -213,4 +213,25 @@ Calculation::EqualSign Calculation::exactAndApproximateDisplayedOutputsAreEqual(
}
}
Calculation::AdditionalOutput Calculation::additionalOuput(Context * context) {
ExpressionNode::Type type = exactOutput().type();
if (type == ExpressionNode::Type::Rational) {
return AdditionalOutput::BaseRepresentation;
}
Preferences * preferences = Preferences::sharedPreferences();
Evaluation<float> e = approximateOutput(context).approximateToEvaluation<float>(context, preferences->complexFormat(), preferences->angleUnit());
if (e.type() == EvaluationNode<float>::Type::MatrixComplex) {
return AdditionalOutput::None;
}
Complex<float> ec = static_cast<Complex<float> &>(e);
// return AdditionalOutput::Matrix
if ((type == ExpressionNode::Type::Cosine || type == ExpressionNode::Type::Sine) && ec.imag() == 0.0f) {
return AdditionalOutput::TrigonometryCircle;
}
if (ec.imag() != 0.0f) {
return AdditionalOutput::ComplexPlan;
}
return AdditionalOutput::None;
}
}

View File

@@ -33,6 +33,14 @@ public:
ExactAndApproximateToggle
};
enum class AdditionalOutput : uint8_t {
None,
ComplexPlan,
TrigonometryCircle,
BaseRepresentation
//Matrix
};
/* It is not really the minimal size, but it clears enough space for most
* calculations instead of clearing less space, then fail to serialize, clear
* more space, fail to serialize, clear more space, etc., until reaching
@@ -67,10 +75,16 @@ public:
Poincare::Layout createExactOutputLayout();
Poincare::Layout createApproximateOutputLayout(Poincare::Context * context);
// Memoization of height
KDCoordinate height(Poincare::Context * context, bool expanded = false);
// Displayed output
DisplayOutput displayOutput(Poincare::Context * context);
bool shouldOnlyDisplayExactOutput();
EqualSign exactAndApproximateDisplayedOutputsAreEqual(Poincare::Context * context);
// Additional outputs
AdditionalOutput additionalOuput(Poincare::Context * context);
private:
static constexpr KDCoordinate k_heightComputationFailureHeight = 50;
/* Buffers holding text expressions have to be longer than the text written

View File

@@ -245,6 +245,8 @@ public:
Coordinate2D<double> nextMaximum(const char * symbol, double start, double step, double max, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
double nextRoot(const char * symbol, double start, double step, double max, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
Coordinate2D<double> nextIntersection(const char * symbol, double start, double step, double max, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, const Expression expression) const;
template<typename U> Evaluation<U> approximateToEvaluation(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
/* This class is meant to contain data about named functions (e.g. sin, tan...)
* in one place: their name, their number of children and a pointer to a builder.
@@ -375,9 +377,6 @@ private:
Expression shallowReduceUsingApproximation(ExpressionNode::ReductionContext reductionContext);
Expression defaultShallowBeautify() { return *this; }
/* Approximation */
template<typename U> Evaluation<U> approximateToEvaluation(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
/* Properties */
int defaultGetPolynomialCoefficients(Context * context, const char * symbol, Expression expression[]) const;