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
=== modified file 'Simple/SimplePage.qml'
--- Simple/SimplePage.qml 2013-09-27 06:21:23 +0000
+++ Simple/SimplePage.qml 2013-09-28 09:32:08 +0000
@@ -86,6 +86,10 @@
86 calculate();86 calculate();
87 }87 }
88 formulaView.headerItem.state = "calculationCompleted";88 formulaView.headerItem.state = "calculationCompleted";
89 // We modify result here to have max precision in the calc, but to have a limited number of decimal displayed
90 // .replace is to avoid to write final 0 in simple calc, because toPrecision add 0
91 // CALC.PRECISION is set in engine.js
92 result = result.toPrecision(CALC.PRECISION).replace(/\.0+$/,"")
89 screenFormula.push({_text:'', _operation: '=', _number: result.toString()});93 screenFormula.push({_text:'', _operation: '=', _number: result.toString()});
90 formulaView.currentOperatorsChanged();94 formulaView.currentOperatorsChanged();
91 }95 }
9296
=== modified file 'engine.js'
--- engine.js 2013-09-10 15:25:42 +0000
+++ engine.js 2013-09-28 09:32:08 +0000
@@ -23,9 +23,7 @@
2323
24// ----------------------------------------24// ----------------------------------------
25// constants (const keyword is not working)25// constants (const keyword is not working)
26var MAX_DECIMAL = 5; // Number of maximum decimal positions
27var PRECISION = 8 // Max lenght of result in exponential mode26var PRECISION = 8 // Max lenght of result in exponential mode
28var MAX_LENGHT = 100000000000 // Highest number before exponential mode
2927
30var RAD = 0, DEG = 1, GRAD = 2; //Trigonometric functions28var RAD = 0, DEG = 1, GRAD = 2; //Trigonometric functions
3129
@@ -550,30 +548,30 @@
550 switch (type) {548 switch (type) {
551 case T_PLUS:549 case T_PLUS:
552 result = lhs.value.plus(rhs.value);550 result = lhs.value.plus(rhs.value);
553 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;551 return result;
554552
555 case T_MINUS:553 case T_MINUS:
556 result = lhs.value.minus(rhs.value);554 result = lhs.value.minus(rhs.value);
557 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;555 return result;
558556
559 case T_TIMES:557 case T_TIMES:
560 result = lhs.value.times(rhs.value);558 result = lhs.value.times(rhs.value);
561 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;559 return result;
562560
563 case T_DIV:561 case T_DIV:
564 result = lhs.value.div(rhs.value);562 result = lhs.value.div(rhs.value);
565 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;563 return result;
566564
567 case T_MOD:565 case T_MOD:
568 if (rhs.value === 0.)566 if (rhs.value === 0.)
569 throw new DivisionByZeroError('modulo division by zero');567 throw new DivisionByZeroError('modulo division by zero');
570568
571 result = lhs.value.mod(rhs.value);569 result = lhs.value.mod(rhs.value);
572 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;570 return result;
573571
574 case T_POW:572 case T_POW:
575 result = lhs.value.pow(rhs.value);573 result = lhs.value.pow(rhs.value);
576 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;574 return result;
577 }575 }
578576
579 // throw?577 // throw?

Subscribers

People subscribed via source and target branches