[gcalctool] Fix order of implied multiplication



commit ca5da825de1d493c7b857af50a7b1fd0f5e7d58e
Author: Robert Ancell <robert ancell canonical com>
Date:   Thu Apr 21 17:32:03 2011 +1000

    Fix order of implied multiplication

 NEWS                     |    1 +
 src/mp-equation-parser.y |    5 ++++-
 src/test-mp-equation.c   |    2 ++
 3 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/NEWS b/NEWS
index c40e1af..09cfda2 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ Overview of changes in gcalctool 6.1.0
     * Add space between number and Ë?C
     * Fix 0^n generating error for fractional n (Bug #634066)
     * Support both μs and us for entering microseconds
+    * Fix order of implied multiplication
 
 Overview of changes in gcalctool 6.0.0
 
diff --git a/src/mp-equation-parser.y b/src/mp-equation-parser.y
index 7f6a890..cb9e49e 100644
--- a/src/mp-equation-parser.y
+++ b/src/mp-equation-parser.y
@@ -174,7 +174,8 @@ static void do_conversion(yyscan_t yyscanner, const MPNumber *x, const char *x_u
 %left UNARY_PLUS
 %left tADD tSUBTRACT
 %left tAND tOR tXOR tXNOR
-%left tMULTIPLY tDIVIDE tMOD MULTIPLICATION
+%left tMULTIPLY MULTIPLICATION
+%left tDIVIDE tMOD
 %left tNOT
 %left tROOT tROOT3 tROOT4
 %left <name> tVARIABLE tFUNCTION
@@ -207,6 +208,8 @@ unit:
 
 exp:
   '(' exp ')' {mp_set_from_mp(&$2, &$$);}
+| exp tDIVIDE exp '(' exp ')' {mp_divide(&$1, &$3, &$$); mp_multiply(&$5, &$$, &$$);}
+| exp tMOD exp '(' exp ')' {mp_modulus_divide(&$1, &$3, &$$); mp_multiply(&$5, &$$, &$$);}
 | exp '(' exp ')' {mp_multiply(&$1, &$3, &$$);}
 | tLFLOOR exp tRFLOOR {mp_floor(&$2, &$$);}
 | tLCEILING exp tRCEILING {mp_ceiling(&$2, &$$);}
diff --git a/src/test-mp-equation.c b/src/test-mp-equation.c
index 47c4662..46fdbf3 100644
--- a/src/test-mp-equation.c
+++ b/src/test-mp-equation.c
@@ -363,6 +363,8 @@ test_equations()
     test("1+(2Ã?3)", "7", 0);
     test("(1+2)Ã?3", "9", 0);
     test("(1+2Ã?3)", "7", 0);
+    test("2(1+1)", "4", 0);
+    test("4÷2(1+1)", "4", 0);
 
     /* Percentage */
     test("100%", "1", 0);



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