[gcalctool] Make inverses of variables work (Bug #614979)
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Make inverses of variables work (Bug #614979)
- Date: Thu, 8 Apr 2010 08:50:08 +0000 (UTC)
commit 268a86a5a630d287beeb85a407f852ce77914827
Author: Robert Ancell <robert ancell gmail com>
Date: Thu Apr 8 18:49:16 2010 +1000
Make inverses of variables work (Bug #614979)
NEWS | 2 ++
src/mp-equation-lexer.l | 2 +-
src/mp-equation-parser.y | 15 +++++++++++++++
src/unittest.c | 3 ++-
4 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index 3b7ddfb..193ef0a 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,8 @@ Overview of changes in gcalctool 5.31.1
* Mark strings for translation that were missing (Gert Kulyk, Bug #614491)
+ * 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 91638ea..5f22ef3 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 9a310e1..766f0f9 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);
@@ -477,7 +478,7 @@ test_equations()
options.angle_units = MP_GRADIANS;
test("sin 100", "1", 0);
-
+
test("0 and 0", "0", 0);
test("1 and 0", "0", 0);
test("0 and 1", "0", 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]