From 8ea5f1b642c3382ebadbefe3c84dc3dd8bf9fab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 17 Apr 2019 12:11:37 +0200 Subject: [PATCH] [apps/calc] If result contains random/round, display approximation only --- apps/calculation/calculation.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index 2a498d278..efa8823d8 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -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. */