[calculation] No special case for unreal calculation, it is handled in

simplication and approximation routines.
This commit is contained in:
Émilie Feral
2018-12-26 18:00:45 +01:00
committed by Léa Saviot
parent ae2de436c2
commit 786cefc3d4
2 changed files with 9 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
#include "../shared/poincare_helpers.h"
#include <poincare/symbol.h>
#include <poincare/undefined.h>
#include <poincare/unreal.h>
#include <string.h>
#include <cmath>
@@ -53,13 +54,6 @@ void Calculation::setContent(const char * c, Context * context, Expression ansEx
PoincareHelpers::ParseAndSimplifyAndApproximate(m_inputText, &exactOutput, &approximateOutput, *context);
PoincareHelpers::Serialize(exactOutput, m_exactOutputText, sizeof(m_exactOutputText));
PoincareHelpers::Serialize(approximateOutput, m_approximateOutputText, sizeof(m_approximateOutputText));
/* Check ComplexFormat: if complex format is real and the input text doesn't
* contain any i complex, both approximate and exact result are set to
* Undefined if the approximate output is not a pure real.*/
if (Preferences::sharedPreferences()->complexFormat() == Preferences::ComplexFormat::Real && strchr(m_inputText, Ion::Charset::IComplex) == nullptr && strchr(m_approximateOutputText, Ion::Charset::IComplex) != nullptr) {
strlcpy(m_exactOutputText, Undefined::Name(), Constant::MaxSerializedExpressionSize);
strlcpy(m_approximateOutputText, Undefined::Name(), Constant::MaxSerializedExpressionSize);
}
}
KDCoordinate Calculation::height(Context * context) {
@@ -161,7 +155,8 @@ bool Calculation::shouldOnlyDisplayApproximateOutput(Context * context) {
* significant digits, the two layouts are not equal, we display both. */
return exactAndApproximateDisplayedOutputsAreEqual(context) == Calculation::EqualSign::Equal;
}
if (strcmp(m_exactOutputText, Undefined::Name()) == 0) {
if (strcmp(m_exactOutputText, Undefined::Name()) == 0 || strcmp(m_approximateOutputText, Unreal::Name()) == 0 ) {
/* if the approximate result is 'unreal' or the exact result is 'undef'*/
return true;
}
return input().isApproximate(*context) || exactOutput().isApproximate(*context);

View File

@@ -120,17 +120,21 @@ QUIZ_CASE(calculation_complex_format) {
Poincare::Preferences::sharedPreferences()->setComplexFormat(Poincare::Preferences::ComplexFormat::Real);
assertCalculationDisplay("1+I", false, true, ::Calculation::Calculation::EqualSign::Unknown, nullptr, "1+I", &globalContext, &store);
assertCalculationDisplay("R(-1)", true, false, ::Calculation::Calculation::EqualSign::Unknown, "undef", nullptr, &globalContext, &store);
assertCalculationDisplay("ln(-2)", true, false, ::Calculation::Calculation::EqualSign::Unknown, "undef", nullptr, &globalContext, &store);
assertCalculationDisplay("R(-1)", false, true, ::Calculation::Calculation::EqualSign::Unknown, "unreal", nullptr, &globalContext, &store);
assertCalculationDisplay("ln(-2)", false, true, ::Calculation::Calculation::EqualSign::Unknown, nullptr, "unreal", &globalContext, &store);
assertCalculationDisplay("R(-1)*R(-1)", false, true, ::Calculation::Calculation::EqualSign::Unknown, nullptr, "unreal", &globalContext, &store);
Poincare::Preferences::sharedPreferences()->setComplexFormat(Poincare::Preferences::ComplexFormat::Cartesian);
assertCalculationDisplay("1+I", false, true, ::Calculation::Calculation::EqualSign::Unknown, nullptr, "1+I", &globalContext, &store);
assertCalculationDisplay("R(-1)", false, true, ::Calculation::Calculation::EqualSign::Unknown, nullptr, "I", &globalContext, &store);
assertCalculationDisplay("ln(-2)", false, false, ::Calculation::Calculation::EqualSign::Approximation, "ln(-2)", nullptr, &globalContext, &store);
assertCalculationDisplay("R(-1)*R(-1)", false, true, ::Calculation::Calculation::EqualSign::Unknown, nullptr, "-1", &globalContext, &store);
Poincare::Preferences::sharedPreferences()->setComplexFormat(Poincare::Preferences::ComplexFormat::Polar);
assertCalculationDisplay("1+I", false, false, ::Calculation::Calculation::EqualSign::Approximation, "R(2)*X^(P/4*I)", nullptr, &globalContext, &store);
assertCalculationDisplay("R(-1)", false, false, ::Calculation::Calculation::EqualSign::Approximation, "X^(P/2*I)", nullptr, &globalContext, &store);
assertCalculationDisplay("ln(-2)", false, false, ::Calculation::Calculation::EqualSign::Approximation, "ln(-2)", nullptr, &globalContext, &store);
assertCalculationDisplay("R(-1)*R(-1)", false, false, ::Calculation::Calculation::EqualSign::Unknown, nullptr, "X^(3.1415926535898*I)", &globalContext, &store);
Poincare::Preferences::sharedPreferences()->setComplexFormat(Poincare::Preferences::ComplexFormat::Cartesian);
}