[gcalctool/gnome-3-0] Fix order of implied multiplication
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool/gnome-3-0] Fix order of implied multiplication
- Date: Thu, 21 Apr 2011 07:59:47 +0000 (UTC)
commit c16bbdc1d5aa952d91cbefcaa6ad48b47558e233
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Apr 21 17:31:55 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 d2d367e..3bd4dbb 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Overview of changes in gcalctool 6.0.1
* Fix crash when not all currencies downloaded
* Fix bit editor (Bug #646142)
* Fix 0^n generating error for fractional n (Bug #634066)
+ * 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 f12b998..5f35010 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]