mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Add a method on expression to know if the expression is equal
to its approximation
This commit is contained in:
@@ -194,16 +194,7 @@ Calculation::EqualSign Calculation::exactAndApproximateDisplayedOutputsAreEqual(
|
||||
if (m_equalSign != EqualSign::Unknown) {
|
||||
return m_equalSign;
|
||||
}
|
||||
char buffer[k_printedExpressionSize];
|
||||
approximateOutput(context)->writeTextInBuffer(buffer, k_printedExpressionSize, Preferences::sharedPreferences()->numberOfSignificantDigits());
|
||||
/* Warning: we cannot use directly the m_approximateOutputText but we have to
|
||||
* re-serialize the approximateOutput because the number of stored
|
||||
* significative numbers and the number of displayed significative numbers
|
||||
* are not identical. (For example, 0.000025 might be displayed "0.00003"
|
||||
* which requires in an approximative equal) */
|
||||
Expression * approximateOutput = Expression::ParseAndSimplify(buffer, *context);
|
||||
m_equalSign = approximateOutput->isIdenticalTo(exactOutput(context)) ? EqualSign::Equal : EqualSign::Approximation;
|
||||
delete approximateOutput;
|
||||
m_equalSign = exactOutput(context)->isEqualToItsApproximationLayout(approximateOutput(context), k_printedExpressionSize, Preferences::sharedPreferences()->numberOfSignificantDigits(), *context) ? EqualSign::Equal : EqualSign::Approximation;
|
||||
return m_equalSign;
|
||||
}
|
||||
|
||||
|
||||
@@ -245,6 +245,7 @@ public:
|
||||
* order on expresssions. */
|
||||
return SimplificationOrder(this, e, true) == 0;
|
||||
}
|
||||
bool isEqualToItsApproximationLayout(Expression * approximation, int bufferSize, int numberOfSignificantDigits, Context & context);
|
||||
|
||||
/* Layout Engine */
|
||||
ExpressionLayout * createLayout(PrintFloat::Mode floatDisplayMode = PrintFloat::Mode::Default, ComplexFormat complexFormat = ComplexFormat::Default) const; // Returned object must be deleted
|
||||
|
||||
@@ -325,6 +325,21 @@ int Expression::SimplificationOrder(const Expression * e1, const Expression * e2
|
||||
}
|
||||
}
|
||||
|
||||
bool Expression::isEqualToItsApproximationLayout(Expression * approximation, int bufferSize, int numberOfSignificantDigits, Context & context) {
|
||||
char buffer[bufferSize];
|
||||
approximation->writeTextInBuffer(buffer, bufferSize, numberOfSignificantDigits);
|
||||
/* Warning: we cannot use directly the the approximate expression but we have
|
||||
* to re-serialize it because the number of stored significative
|
||||
* numbers and the number of displayed significative numbers might not be
|
||||
* identical. (For example, 0.000025 might be displayed "0.00003" and stored
|
||||
* as Decimal(0.000025) and isEqualToItsApproximationLayout should return
|
||||
* false) */
|
||||
Expression * approximateOutput = Expression::ParseAndSimplify(buffer, context);
|
||||
bool equal = isIdenticalTo(approximateOutput);
|
||||
delete approximateOutput;
|
||||
return equal;
|
||||
}
|
||||
|
||||
/* Layout */
|
||||
|
||||
ExpressionLayout * Expression::createLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
|
||||
Reference in New Issue
Block a user