[apps/calc] If result contains random/round, display approximation only

This commit is contained in:
Léa Saviot
2019-04-17 12:11:37 +02:00
committed by Émilie Feral
parent a8e7208a30
commit 8ea5f1b642

View File

@@ -159,7 +159,15 @@ Calculation::DisplayOutput Calculation::displayOutput(Context * context) {
return DisplayOutput::ExactOnly;
}
bool approximateOnly = false;
if (strcmp(m_exactOutputText, m_approximateOutputText) == 0) {
if (exactOutput().recursivelyMatches([](const Expression e, Context & c, bool replaceSymbols) {
/* If the exact result contains one of the following types, do not
* display it. */
ExpressionNode::Type t = e.type();
return (t == ExpressionNode::Type::Random) || (t == ExpressionNode::Type::Round);},
*context, true))
{
approximateOnly = true;
} else if (strcmp(m_exactOutputText, m_approximateOutputText) == 0) {
/* If the exact and approximate results' texts are equal and their layouts
* too, do not display the exact result. If the two layouts are not equal
* because of the number of significant digits, we display both. */