[gcalctool] Percentage operation for addition and subtraction now takes percentage of first value (Robert Ancell



commit 6b50d96b8258b5757aae05c02d2cc0fdebd4e0b7
Author: Robert Ancell <robert ancell gmail com>
Date:   Mon Jun 15 17:37:53 2009 +1000

    Percentage operation for addition and subtraction now takes percentage of first value (Robert Ancell, Bug #480207)

 ChangeLog                |    5 +++++
 src/mp-equation-parser.y |    3 +++
 src/unittest.c           |    4 ++++
 3 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9c46bf5..2f4ea1c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,11 @@
 gcalctool change history.
 =========================
 
+2009-06-15 Robert Ancell <robert ancell gmail com>
+
+    * Percentage operation for addition and subtraction now takes percentage of
+      first value (Robert Ancell, Bug #480207)
+
 2009-05-27 Robert Ancell <robert ancell gmail com>
 
     * Focus on the display entry by default
diff --git a/src/mp-equation-parser.y b/src/mp-equation-parser.y
index 8f62e21..c301818 100644
--- a/src/mp-equation-parser.y
+++ b/src/mp-equation-parser.y
@@ -141,6 +141,9 @@ value:
 exp: 
   term {mp_set_from_mp(&$1, &$$);}
 
+| exp '+' term '%' {mp_add_integer(&$3, 100, &$3); mp_divide_integer(&$3, 100, &$3); mp_multiply(&$1, &$3, &$$);}
+| exp '-' term '%' {mp_add_integer(&$3, -100, &$3); mp_divide_integer(&$3, -100, &$3); mp_multiply(&$1, &$3, &$$);}
+
 | exp '+' exp {mp_add(&$1, &$3, &$$);}
 | exp '-' exp {mp_subtract(&$1, &$3, &$$);}
 
diff --git a/src/unittest.c b/src/unittest.c
index 8052a0f..1439b13 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -149,6 +149,10 @@ test_parser()
     
     test("100%", "1", 0);
     test("1%", "0.01", 0);
+    test("100+1%", "101", 0);
+    test("100-1%", "99", 0);
+    test("100*1%", "1", 0);
+    test("100/1%", "10000", 0);    
 
     test("0!", "1", 0);
     test("1!", "1", 0);



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