Merge lp:~rpadovani/ubuntu-calculator-app/1232058 into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk

Proposed by Riccardo Padovani
Status: Merged
Approved by: Mihir Soni
Approved revision: 164
Merged at revision: 166
Proposed branch: lp:~rpadovani/ubuntu-calculator-app/1232058
Merge into: lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk
Diff against target: 65 lines (+10/-8)
2 files modified
Simple/SimplePage.qml (+4/-0)
engine.js (+6/-8)
To merge this branch: bzr merge lp:~rpadovani/ubuntu-calculator-app/1232058
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Mihir Soni Approve
Review via email: mp+188194@code.launchpad.net

Commit message

Update engine to better precision:
- now can continue also exponetial calc
- now also decimal result has a limit

Fixed #1232058

Description of the change

Update engine to better precision:
- now can continue also exponetial calc
- now also decimal result has a limit

Fixed #1232058

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

Works great :)

Thanks a lot for your time :)

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Simple/SimplePage.qml'
2--- Simple/SimplePage.qml 2013-09-27 06:21:23 +0000
3+++ Simple/SimplePage.qml 2013-09-28 09:32:08 +0000
4@@ -86,6 +86,10 @@
5 calculate();
6 }
7 formulaView.headerItem.state = "calculationCompleted";
8+ // We modify result here to have max precision in the calc, but to have a limited number of decimal displayed
9+ // .replace is to avoid to write final 0 in simple calc, because toPrecision add 0
10+ // CALC.PRECISION is set in engine.js
11+ result = result.toPrecision(CALC.PRECISION).replace(/\.0+$/,"")
12 screenFormula.push({_text:'', _operation: '=', _number: result.toString()});
13 formulaView.currentOperatorsChanged();
14 }
15
16=== modified file 'engine.js'
17--- engine.js 2013-09-10 15:25:42 +0000
18+++ engine.js 2013-09-28 09:32:08 +0000
19@@ -23,9 +23,7 @@
20
21 // ----------------------------------------
22 // constants (const keyword is not working)
23-var MAX_DECIMAL = 5; // Number of maximum decimal positions
24 var PRECISION = 8 // Max lenght of result in exponential mode
25-var MAX_LENGHT = 100000000000 // Highest number before exponential mode
26
27 var RAD = 0, DEG = 1, GRAD = 2; //Trigonometric functions
28
29@@ -550,30 +548,30 @@
30 switch (type) {
31 case T_PLUS:
32 result = lhs.value.plus(rhs.value);
33- return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
34+ return result;
35
36 case T_MINUS:
37 result = lhs.value.minus(rhs.value);
38- return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
39+ return result;
40
41 case T_TIMES:
42 result = lhs.value.times(rhs.value);
43- return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
44+ return result;
45
46 case T_DIV:
47 result = lhs.value.div(rhs.value);
48- return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
49+ return result;
50
51 case T_MOD:
52 if (rhs.value === 0.)
53 throw new DivisionByZeroError('modulo division by zero');
54
55 result = lhs.value.mod(rhs.value);
56- return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
57+ return result;
58
59 case T_POW:
60 result = lhs.value.pow(rhs.value);
61- return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
62+ return result;
63 }
64
65 // throw?

Subscribers

People subscribed via source and target branches