[gnome-calculator] Fixed missing implicit multiplication with variable and root (fixes #279)



commit c66aacba4d40b775b145cf4ec96bdeb7b22db5e1
Author: Robert Roth <robert roth off gmail com>
Date:   Mon May 30 08:48:06 2022 +0300

    Fixed missing implicit multiplication with variable and root (fixes #279)

 lib/equation-parser.vala | 8 +++-----
 tests/test-equation.vala | 3 +++
 2 files changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/lib/equation-parser.vala b/lib/equation-parser.vala
index 6445d79f..7c67912b 100644
--- a/lib/equation-parser.vala
+++ b/lib/equation-parser.vala
@@ -2155,14 +2155,12 @@ public class Parser
         if (token.type == LexerTokenType.PL_EOS || token.type == LexerTokenType.ASSIGN)
             return true;
 
-        if (token.type == LexerTokenType.VARIABLE)
+        if (token.type == LexerTokenType.FUNCTION || token.type == LexerTokenType.VARIABLE || token.type == 
LexerTokenType.SUB_NUMBER || token.type == LexerTokenType.ROOT || token.type == LexerTokenType.ROOT_3 || 
token.type == LexerTokenType.ROOT_4)
         {
-            /* Insert multiply in between two distinct (variable). */
+            /* Insert multiply in between variable and (function, variable, root) */
             insert_into_tree (new MultiplyNode (this, null, make_precedence_p (Precedence.MULTIPLY), 
get_associativity_p (Precedence.MULTIPLY)));
-
-            if (!term ())
+            if (!variable ())
                 return false;
-
             return true;
         }
         else
diff --git a/tests/test-equation.vala b/tests/test-equation.vala
index 336708c1..85fe7c4f 100644
--- a/tests/test-equation.vala
+++ b/tests/test-equation.vala
@@ -476,6 +476,9 @@ private void test_equations ()
     test ("₁₀√1024", "2", 0);
     test ("√(2+2)", "2", 0);
     test ("2√4", "4", 0);
+    test ("x", "2", 0);
+    test ("x√4", "4", 0);
+    test ("x∛8", "4", 0);
     test ("2×√4", "4", 0);
     test ("Sqrt (4)", "2", 0);
     test ("Sqrt (2)", "1.414213562", 0);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]