Merge lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-temporarly-result-fix into lp:ubuntu-calculator-app

Proposed by Bartosz Kosiorek
Status: Merged
Approved by: Bartosz Kosiorek
Approved revision: 177
Merged at revision: 172
Proposed branch: lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-temporarly-result-fix
Merge into: lp:ubuntu-calculator-app
Diff against target: 160 lines (+46/-33)
2 files modified
app/ubuntu-calculator-app.qml (+40/-27)
tests/autopilot/ubuntu_calculator_app/tests/test_main.py (+6/-6)
To merge this branch: bzr merge lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-temporarly-result-fix
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Alan Pope 🍺🐧🐱 πŸ¦„ (community) Approve
Review via email: mp+257447@code.launchpad.net

Commit message

Temporary result fix

Description of the change

Temporary result fix

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Looks good! Thanks for fixing this.

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Are you re-running and expecting it to pass? Seems to fail randomly?

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Have run the calculation manually on the phone as per this test:-

    def test_operation_on_large_numbers(self):
        self.app.main_view.insert('99999999999*99999999999=')
        self._assert_result_is(u'9.9999999998e+21')
        self._assert_history_contains(u'99999999999Γ—99999999999='
                                      '9.9999999998e+21')

        self.app.main_view.insert('*100=')

        self._assert_result_is(u'9.9999999998e+23')
        self._assert_history_contains(u'9.9999999998e+21Γ—100='
                                      '9.9999999998e+23')

I get 9.9999999998e+23 on the calculator in the store on my mx4.
I get 9.0000000998e+23 on this branch in on my bq phone.

So it seems the new library is a bit broken still.

Revision history for this message
Bartosz Kosiorek (gang65) wrote :

Thanks Alan.
Unfortunately we cannot do much with that.
The bug was reported on bignumber.js/decimal.js, here
https://github.com/MikeMcl/decimal.js/issues/15

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 'app/ubuntu-calculator-app.qml'
2--- app/ubuntu-calculator-app.qml 2015-04-24 16:22:05 +0000
3+++ app/ubuntu-calculator-app.qml 2015-04-26 22:42:08 +0000
4@@ -101,10 +101,36 @@
5 displayedInputText = "";
6 }
7
8+ /**
9+ * Format bigNumber
10+ */
11+ function formatBigNumber(bigNumberToFormat) {
12+
13+ // Maximum length of the result number
14+ var NUMBER_LENGTH_LIMIT = 14;
15+
16+ if (mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}}).length > NUMBER_LENGTH_LIMIT) {
17+ if (bigNumberToFormat.toExponential().length > NUMBER_LENGTH_LIMIT) {
18+ // long format like: "1.2341322e+22"
19+ var resultLenth = mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
20+ precision: NUMBER_LENGTH_LIMIT}).length;
21+
22+ return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
23+ precision: (NUMBER_LENGTH_LIMIT - resultLenth + NUMBER_LENGTH_LIMIT)});
24+ } else {
25+ // short format like: "1e-10"
26+ return bigNumberToFormat.toExponential();
27+ }
28+ } else {
29+ // exponential: Object An object containing two parameters, {Number} lower and {Number} upper,
30+ // used by notation 'auto' to determine when to return exponential notation.
31+ return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}});
32+ }
33+ }
34+
35 function formulaPush(visual) {
36 mathJs.config({
37- number: 'bignumber', // Choose 'number' (default) or 'bignumber'
38- precision: 64
39+ number: 'bignumber'
40 });
41 // If the user press a number after the press of "=" we start a new
42 // formula, otherwise we continue with the old one
43@@ -136,7 +162,7 @@
44 // we display a temporary result instead the all operation
45 if (isNaN(visual) && (visual.toString() !== ".") && isFormulaIsValidToCalculate) {
46 try {
47- shortFormula = mathJs.eval(shortFormula);
48+ shortFormula = formatBigNumber(mathJs.eval(shortFormula));
49 } catch(exception) {
50 console.log("Error: math.js " + exception.toString() + " engine formula:" + shortFormula);
51 }
52@@ -148,14 +174,16 @@
53 if (textInputField.cursorPosition === textInputField.length ) {
54 longFormula += visual.toString();
55 shortFormula += visual.toString();
56+ displayedInputText = shortFormula;
57 } else {
58 longFormula = longFormula.slice(0, textInputField.cursorPosition) + visual.toString() + longFormula.slice(textInputField.cursorPosition, longFormula.length);
59 shortFormula = longFormula;
60+ var preservedCursorPosition = textInputField.cursorPosition;
61+ displayedInputText = shortFormula;
62+ textInputField.cursorPosition = preservedCursorPosition + visual.length;
63 }
64
65- var preservedCursorPosition = textInputField.cursorPosition;
66- displayedInputText = shortFormula;
67- textInputField.cursorPosition = preservedCursorPosition + visual.length;
68+
69
70 // Add here operators that have always priority
71 if ((visual.toString() === "*") || (visual.toString() === ")")) {
72@@ -165,8 +193,7 @@
73
74 function calculate() {
75 mathJs.config({
76- number: 'bignumber', // Choose 'number' (default) or 'bignumber'
77- precision: 64
78+ number: 'bignumber'
79 });
80 if ((longFormula === '') || (isLastCalculate === true)) {
81 errorAnimation.restart();
82@@ -184,20 +211,8 @@
83 try {
84 var result = mathJs.eval(longFormula);
85
86- // Maximum length of the result number
87- var NUMBER_LENGTH_LIMIT = 12;
88+ result = formatBigNumber(result)
89
90- if (mathJs.format(result).toString().length > NUMBER_LENGTH_LIMIT) {
91- if (result.toExponential().toString().length > NUMBER_LENGTH_LIMIT) {
92- // long format like: "1.2341322e+22"
93- result = mathJs.format(result, {notation: 'auto', precision: NUMBER_LENGTH_LIMIT});
94- } else {
95- // short format like: "1e-10"
96- result = result.toExponential();
97- }
98- } else {
99- result = mathJs.format(result)
100- }
101 } catch(exception) {
102 // If the formula isn't right and we added brackets, we remove them
103 for (var i = 0; i < numberOfOpenedBrackets; i++) {
104@@ -208,8 +223,6 @@
105 return false;
106 }
107
108- result = result.toString()
109-
110 isLastCalculate = true;
111 if (result === longFormula) {
112 errorAnimation.restart();
113@@ -582,9 +595,9 @@
114 textInputField.forceActiveFocus();
115 if (editedCalculationIndex >= 0) {
116 calculationHistory.updateCalculationInDatabase(editedCalculationIndex,
117- calculationHistory.getContents().get(editedCalculationIndex).dbId,
118- true,
119- favouriteTextField.text);
120+ calculationHistory.getContents().get(editedCalculationIndex).dbId,
121+ true,
122+ favouriteTextField.text);
123 favouriteTextField.text = "";
124 editedCalculationIndex = -1;
125 }
126@@ -657,7 +670,7 @@
127 width: parent.width
128 source: scrollableView.width > scrollableView.height ? "ui/LandscapeKeyboard.qml" : "ui/PortraitKeyboard.qml"
129 opacity: ((y + height) >= scrollableView.contentY) &&
130- (y <= (scrollableView.contentY + scrollableView.height)) ? 1 : 0
131+ (y <= (scrollableView.contentY + scrollableView.height)) ? 1 : 0
132 }
133 }
134 }
135
136=== modified file 'tests/autopilot/ubuntu_calculator_app/tests/test_main.py'
137--- tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-04-24 19:58:17 +0000
138+++ tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-04-26 22:42:08 +0000
139@@ -95,15 +95,15 @@
140 self._assert_history_contains(u'9Γ—9=81')
141
142 def test_small_numbers(self):
143- self.app.main_view.insert('0.000000001+1=')
144- self._assert_result_is(u'1.000000001')
145- self._assert_history_contains(u'0.000000001+1=1.000000001')
146+ self.app.main_view.insert('0.0000000001+1=')
147+ self._assert_result_is(u'1.0000000001')
148+ self._assert_history_contains(u'0.0000000001+1=1.0000000001')
149
150 self.app.main_view.delete()
151
152- self.app.main_view.insert('0.000000001/10=')
153- self._assert_result_is(u'1eβˆ’10')
154- self._assert_history_contains(u'0.000000001Γ·10=1eβˆ’10')
155+ self.app.main_view.insert('0.0000000001/10=')
156+ self._assert_result_is(u'1eβˆ’11')
157+ self._assert_history_contains(u'0.0000000001Γ·10=1eβˆ’11')
158
159 def test_operation_on_large_numbers(self):
160 self.app.main_view.insert('99999999999*99999999999=')

Subscribers

People subscribed via source and target branches