[gnome-calculator] equation: fix precedence of the root operator with regards to the unary minus
- From: Alberto Ruiz <aruiz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] equation: fix precedence of the root operator with regards to the unary minus
- Date: Fri, 15 Apr 2016 23:22:27 +0000 (UTC)
commit 87f716dacc58a0cebf69142ab10a621ffdf1d907
Author: Alberto Ruiz <aruiz gnome org>
Date: Sat Apr 16 00:22:06 2016 +0100
equation: fix precedence of the root operator with regards to the unary minus
lib/equation-parser.vala | 18 +++++++++---------
tests/test-equation.vala | 1 +
2 files changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/lib/equation-parser.vala b/lib/equation-parser.vala
index 0c3ce6d..b00224d 100644
--- a/lib/equation-parser.vala
+++ b/lib/equation-parser.vala
@@ -26,15 +26,15 @@ private enum Precedence
MOD = 3,
DIVIDE = 3,
NOT = 4,
- ROOT = 5,
- FUNCTION = 6,
- BOOLEAN = 7,
- PERCENTAGE = 8,
- /* UNARY_MINUS and POWER must have same precedence. */
- UNARY_MINUS = 9,
- POWER = 9,
- FACTORIAL = 10,
- NUMBER_VARIABLE = 11,
+ FUNCTION = 5,
+ BOOLEAN = 6,
+ PERCENTAGE = 7,
+ /* UNARY_MINUS, ROOT and POWER must have same precedence. */
+ UNARY_MINUS = 8,
+ POWER = 8,
+ ROOT = 8,
+ FACTORIAL = 9,
+ NUMBER_VARIABLE = 10,
/* DEPTH should be always at the bottom. It stops node jumping off the current depth level. */
DEPTH
}
diff --git a/tests/test-equation.vala b/tests/test-equation.vala
index bde8e9e..4a4d561 100644
--- a/tests/test-equation.vala
+++ b/tests/test-equation.vala
@@ -689,6 +689,7 @@ private void test_precedence ()
test ("- 4!", "−24", 0);
test ("3! ^ 3", "216", 0);
test ("3 ^ 3!", "729", 0);
+ test ("(−√3)^2", "3", 0);
}
private void test_custom_functions ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]