[gcalctool] Make variable powers work, e.g. x²



commit 49f41ff4f6276599fe7a139a990175b67abf7b9a
Author: Robert Ancell <robert ancell gmail com>
Date:   Mon Mar 1 16:45:54 2010 +1100

    Make variable powers work, e.g. x²

 NEWS                     |    2 ++
 src/mp-equation-parser.y |    1 +
 src/unittest.c           |    9 +++++----
 3 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index e87fedd..367a270 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,8 @@ Overview of changes in gcalctool 5.29.92
 
     * Make bit editor active for displayed numbers not in base 10
 
+    * Make variable powers work, e.g. x²
+
 Overview of changes in gcalctool 5.29.91
 
     * Fix bug where backspace deletes all input in locales with no thousands
diff --git a/src/mp-equation-parser.y b/src/mp-equation-parser.y
index f5e7690..89c6cc3 100644
--- a/src/mp-equation-parser.y
+++ b/src/mp-equation-parser.y
@@ -160,6 +160,7 @@ exp:
 
 variable:
   tVARIABLE exp {if (!get_function(yyscanner, $1, &$2, &$$)) YYABORT; free($1);}
+| tVARIABLE tSUPNUM {MPNumber t; if (!get_variable(yyscanner, $1, &t)) YYABORT; mp_xpowy_integer(&t, $2, &$$);; free($1);}
 | tVARIABLE tSUPNUM exp {if (!get_function(yyscanner, $1, &$3, &$$)) YYABORT; mp_xpowy_integer(&$$, $2, &$$); free($1);}
 | tSUBNUM tROOT exp {mp_root(&$3, $1, &$$);}
 | tROOT exp {mp_sqrt(&$2, &$$);}
diff --git a/src/unittest.c b/src/unittest.c
index 7bd0146..e444ec4 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -181,15 +181,16 @@ test_parser()
 
     test("Ï?", "3.141592654", 0);
     test("e", "2.718281828", 0);
+    test("e²", "7.389056099", 0);
     test("2Ï?", "6.283185307", 0);
     test("2e", "5.436563657", 0);
-    //test("2Ï?²", "19.739208802", 0);
-    //test("2e²", "14.778112198", 0);
+    test("2Ï?²", "19.739208802", 0);
+    test("2e²", "14.778112198", 0);
     test("e2", "", PARSER_ERR_UNKNOWN_FUNCTION);
     test("Ï?2", "", PARSER_ERR_UNKNOWN_FUNCTION);
     test("Ï?e", "8.539734223", 0);
     test("eÏ?", "8.539734223", 0);
-    //test("2Ï?e", "17.079468445", 0);
+    test("2Ï?e", "17.079468445", 0);
 
     test("0+0", "0", 0);
     test("1+1", "2", 0);
@@ -364,7 +365,7 @@ test_parser()
     test("sinh 10 â?? (e^10 â?? e^â??10)÷2", "0", 0);
     test("sinh (â??10) + sinh 10", "0", 0);
 
-    test("cosh² â??5 â?? sinh² â??5", "1", 0);
+    test("cosh² (â??5) â?? sinh² (â??5)", "1", 0);
     test("tanh 0", "0", 0);
     test("tanh 10 â?? sinh 10 ÷ cosh 10", "0", 0);
 



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