From ca5da825de1d493c7b857af50a7b1fd0f5e7d58e Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 21 Apr 2011 17:32:03 +1000 Subject: [PATCH] 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 deletion(-) diff --git a/NEWS b/NEWS index c40e1af4..09cfda25 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 7f6a890b..cb9e49e1 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 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 47c46627..46fdbf37 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); -- 2.11.4.GIT