[gcalctool/gnome-2-30] Make inverses of variables work (Bug #614979)
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool/gnome-2-30] Make inverses of variables work (Bug #614979)
- Date: Tue, 6 Apr 2010 23:44:14 +0000 (UTC)
commit c1496d13a688523e6b2e6cc4ea1b3cc336c42a68
Author: Robert Ancell <robert ancell gmail com>
Date: Wed Apr 7 09:43:46 2010 +1000
Make inverses of variables work (Bug #614979)
NEWS | 4 +++-
src/mp-equation-lexer.l | 2 +-
src/mp-equation-parser.y | 15 +++++++++++++++
src/unittest.c | 1 +
4 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index 55e8cf8..c5c2794 100644
--- a/NEWS
+++ b/NEWS
@@ -11,7 +11,9 @@ Overview of changes in gcalctool 5.30.1
* Mark strings for translation that were missing (Gert Kulyk, Bug #614491)
* Fix memory leak in gcalccmd and failure to quit on EOF (Bug #614875)
-
+
+ * Make inverses of variables work (Bug #614979)
+
Overview of changes in gcalctool 5.30.0
* Fix errors in variable exponents (e.g. xy²)
diff --git a/src/mp-equation-lexer.l b/src/mp-equation-lexer.l
index 1172aa0..1942566 100644
--- a/src/mp-equation-lexer.l
+++ b/src/mp-equation-lexer.l
@@ -64,7 +64,7 @@ DEC_NUM {DEC}+|{DEC}*{DECIMAL}{DEC}+
BASE_NUM {HEX}+{SUB_NUM}|{HEX}*{DECIMAL}{HEX}+{SUB_NUM}
NUMBER {DEC_NUM}|{BASE_NUM}|{FRACTION}|{DEC_NUM}{FRACTION}
-VARIABLE {WORD}|{WORD}{SUB_NUM}|{WORD}"�¹"|{GREEKS}
+VARIABLE {WORD}|{WORD}{SUB_NUM}|{GREEKS}
MOD [mM][oO][dD]
AND "â?§"|[aA][nN][dD]
diff --git a/src/mp-equation-parser.y b/src/mp-equation-parser.y
index 96d0fc9..c4696fb 100644
--- a/src/mp-equation-parser.y
+++ b/src/mp-equation-parser.y
@@ -114,6 +114,20 @@ static int get_function(yyscan_t yyscanner, const char *name, const MPNumber *x,
return 1;
}
+static int get_inverse_function(yyscan_t yyscanner, const char *name, const MPNumber *x, MPNumber *z)
+{
+ char *inv_name;
+ int result;
+
+ inv_name = malloc(sizeof(char) * (strlen(name) + strlen("�¹") + 1));
+ strcpy(inv_name, name);
+ strcat(inv_name, "�¹");
+ result = get_function(yyscanner, inv_name, x, z);
+ free(inv_name);
+
+ return result;
+}
+
static void do_not(yyscan_t yyscanner, const MPNumber *x, MPNumber *z)
{
if (!mp_is_overflow(x, _mp_equation_get_extra(yyscanner)->options->wordlen)) {
@@ -230,6 +244,7 @@ variable:
term {mp_set_from_mp(&$1, &$$);}
| tFUNCTION exp {if (!get_function(yyscanner, $1, &$2, &$$)) YYABORT; free($1);}
| tFUNCTION tSUPNUM exp {if (!get_function(yyscanner, $1, &$3, &$$)) YYABORT; mp_xpowy_integer(&$$, $2, &$$); free($1);}
+| tFUNCTION tNSUPNUM exp {if (!get_inverse_function(yyscanner, $1, &$3, &$$)) YYABORT; mp_xpowy_integer(&$$, -$2, &$$); free($1);}
| tVARIABLE tSUPNUM exp {set_error(yyscanner, PARSER_ERR_UNKNOWN_FUNCTION, $1); free($1); YYABORT;}
| tSUBNUM tROOT exp {mp_root(&$3, $1, &$$);}
| tROOT exp {mp_sqrt(&$2, &$$);}
diff --git a/src/unittest.c b/src/unittest.c
index 147480e..3df242c 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -364,6 +364,7 @@ test_equations()
//test("2â?»", "", PARSER_ERR_MP); // FIXME: Maybe an error in bison?
test("2^â??1", "0.5", 0);
test("2^(â??1)", "0.5", 0);
+ test("x�¹", "0.5", 0);
test("â??10^2", "â??100", 0);
test("(â??10)^2", "100", 0);
test("â??(10^2)", "â??100", 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]