Merge lp:~lexsurkov/pantheon-calculator/Bug_1465680 into lp:~elementary-apps/pantheon-calculator/trunk

Proposed by lexsurkov
Status: Rejected
Rejected by: Danielle Foré
Proposed branch: lp:~lexsurkov/pantheon-calculator/Bug_1465680
Merge into: lp:~elementary-apps/pantheon-calculator/trunk
Diff against target: 45 lines (+10/-2)
2 files modified
src/Core/Evaluation.vala (+9/-1)
src/Core/Scanner.vala (+1/-1)
To merge this branch: bzr merge lp:~lexsurkov/pantheon-calculator/Bug_1465680
Reviewer Review Type Date Requested Status
xapantu (community) Disapprove
Review via email: mp+270140@code.launchpad.net

Commit message

Fixed Bug #1465680 Incorrectly calculating of percentages

Description of the change

Fixed Bug #1465680 Incorrectly calculating of percentages

To post a comment you must log in.
Revision history for this message
xapantu (xapantu) wrote :

Unfortunately we are discussing the bug you linked, I am not sure we reached an agreement yet =(

But I am rather sure we will not want what was described in the bug report.

review: Disapprove
Revision history for this message
lexsurkov (lexsurkov) wrote :

I am think, you must test the commit. I not destroyed work the calculator, but made corrections like making step by step calculator. I do not insist that it is the right solution, but maybe there will be new ideas.

Unmerged revisions

160. By lexsurkov

Fixed Bug #1465680 Incorrectly calculating of percentages

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Core/Evaluation.vala'
2--- src/Core/Evaluation.vala 2015-04-03 12:04:47 +0000
3+++ src/Core/Evaluation.vala 2015-09-04 06:42:16 +0000
4@@ -55,6 +55,7 @@
5 Operator () { symbol = "mod", inputs = 2, prec = 2, fixity = "LEFT", eval = (a, b) => { return a % b; } },
6 Operator () { symbol = "^", inputs = 2, prec = 3, fixity = "RIGHT", eval = (a, b) => { return Math.pow (a, b); } },
7 Operator () { symbol = "E", inputs = 2, prec = 4, fixity = "RIGHT", eval = (a, b) => { return a*Math.pow (10, b); } },
8+ Operator () { symbol = "prc", inputs = 2, prec = 5, fixity = "LEFT", eval = (a, b) => { return (a * b) / 100; } },
9 Operator () { symbol = "%", inputs = 1, prec = 5, fixity = "LEFT", eval = (a, b) => { return b / 100.0;} } };
10
11 private struct Function { string symbol; int inputs; Eval eval;}
12@@ -186,12 +187,19 @@
13 } catch (SHUNTING_ERROR e) { throw new EVAL_ERROR.NO_CONSTANT (""); }
14 } else if (t.token_type == TokenType.OPERATOR) {
15 try {
16+ if (t.content == "%" && t != token_list.last ().data) {
17+ Token next_token = token_list.nth (token_list.index (t) + 1).data;
18+ if (next_token.token_type == TokenType.OPERATOR && (next_token.content == "-" || next_token.content == "+"))
19+ t = new Token ("prc", TokenType.OPERATOR);
20+ }
21 Operator o = get_operator (t);
22 Token t1 = stack.pop ();
23 Token t2 = new Token ("0", TokenType.NUMBER);
24
25- if (!stack.is_length (0) && o.inputs == 2)
26+ if (!stack.is_length (0) && o.inputs == 2 && t.content != "prc")
27 t2 = stack.pop ();
28+ else if ((!stack.is_length (0) && o.inputs == 2 && t.content == "prc"))
29+ t2 = stack.peek ();
30 stack.push (compute_tokens (t, t1, t2));
31 } catch (SHUNTING_ERROR e) { throw new EVAL_ERROR.NO_OPERATOR (""); }
32 } else if (t.token_type == TokenType.FUNCTION) {
33
34=== modified file 'src/Core/Scanner.vala'
35--- src/Core/Scanner.vala 2015-04-05 08:14:49 +0000
36+++ src/Core/Scanner.vala 2015-09-04 06:42:16 +0000
37@@ -81,7 +81,7 @@
38
39 } else if (t.token_type == TokenType.OPERATOR && t.content == "-") {
40 if (last_token == null || (last_token != null && last_token.token_type != TokenType.NUMBER &&
41- last_token.token_type != TokenType.P_RIGHT)) {
42+ last_token.token_type != TokenType.P_RIGHT && last_token.content != "%")) {
43 next_number_negative = true;
44 continue;
45 }

Subscribers

People subscribed via source and target branches

to all changes: