← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-long-complex-numbers-fix into lp:ubuntu-calculator-app

 

Bartosz Kosiorek has proposed merging lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-long-complex-numbers-fix into lp:ubuntu-calculator-app.

Commit message:
Fix evaluation of long complex numbers (LP: #1515600)


Requested reviews:
  Ubuntu Calculator Developers (ubuntu-calculator-dev)
Related bugs:
  Bug #1515600 in Ubuntu Calculator App: "Unable to evaluate "(3+4i)^2" formula with BigNumbers"
  https://bugs.launchpad.net/ubuntu-calculator-app/+bug/1515600

For more details, see:
https://code.launchpad.net/~gang65/ubuntu-calculator-app/ubuntu-calculator-app-long-complex-numbers-fix/+merge/277345

Fix evaluation of long complex numbers (LP: #1515600)

-- 
Your team Ubuntu Calculator Developers is requested to review the proposed merge of lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-long-complex-numbers-fix into lp:ubuntu-calculator-app.
=== modified file 'app/ubuntu-calculator-app.qml'
--- app/ubuntu-calculator-app.qml	2015-10-28 20:56:47 +0000
+++ app/ubuntu-calculator-app.qml	2015-11-12 12:53:36 +0000
@@ -110,23 +110,12 @@
 
         // Maximum length of the result number
         var NUMBER_LENGTH_LIMIT = 14;
-
-        if (mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}}).length > NUMBER_LENGTH_LIMIT) {
-            if (bigNumberToFormat.toExponential().length > NUMBER_LENGTH_LIMIT) {
-                // long format like: "1.2341322e+22"
-                var resultLenth = mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
-                                                precision: NUMBER_LENGTH_LIMIT}).length;
-
-                return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
-                                                precision: (NUMBER_LENGTH_LIMIT - resultLenth + NUMBER_LENGTH_LIMIT)});
-            } else {
-                // short format like: "1e-10"
-                return bigNumberToFormat.toExponential();
-            }
-        } else {
-            // exponential: Object An object containing two parameters, {Number} lower and {Number} upper, 
-            // used by notation 'auto' to determine when to return exponential notation.
-            return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}});
+        if (bigNumberToFormat.toString().length > NUMBER_LENGTH_LIMIT) {
+            var resultLength = mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
+                                            precision: NUMBER_LENGTH_LIMIT}).length;
+
+            return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
+                                 precision: (NUMBER_LENGTH_LIMIT - resultLength + NUMBER_LENGTH_LIMIT)});
         }
     }
 

=== modified file 'debian/changelog'
--- debian/changelog	2015-11-05 23:50:40 +0000
+++ debian/changelog	2015-11-12 12:53:36 +0000
@@ -1,4 +1,11 @@
-ubuntu-calculator-app (2.0.210) UNRELEASED; urgency=medium
+ubuntu-calculator-app (2.1) UNRELEASED; urgency=medium
+
+  [ Bartosz Kosiorek ]
+  * Fix evaluation of long complex numbers (LP: #1515600)
+
+ -- Bartosz Kosiorek <gang65@xxxxxxxxxxxxxx>  Thu, 12 Nov 2015 13:28:29 +0100
+
+ubuntu-calculator-app (2.0.233) vivid; urgency=medium
 
   [ Bartosz Kosiorek ]
   * Fixes in creating .deb package (LP: #1466518) (LP: #1466530) (LP: #1468385)

=== modified file 'tests/autopilot/ubuntu_calculator_app/tests/test_main.py'
--- tests/autopilot/ubuntu_calculator_app/tests/test_main.py	2015-07-10 21:07:19 +0000
+++ tests/autopilot/ubuntu_calculator_app/tests/test_main.py	2015-11-12 12:53:36 +0000
@@ -345,6 +345,21 @@
         self._assert_result_is(u'−66')
         self._assert_history_contains(u'66i×i=−66')
 
+    def test_formatting_long_complex_numbers(self):
+        self.app.main_view.press_universal_bracket()
+        self.app.main_view.insert('3+4')
+        self.app.main_view.show_scientific_keyboard()
+        self.app.main_view.press('i')
+        self.app.main_view.hide_scientific_keyboard()
+        self.app.main_view.press_universal_bracket()
+        self.app.main_view.show_scientific_keyboard()
+        self.app.main_view.press('square')
+        self._assert_result_is(u'(3+4i)^2')
+        self.app.main_view.hide_scientific_keyboard()
+        self.app.main_view.insert('=')
+        self._assert_result_is(u'−6.999999999999997+24i')
+        self._assert_history_contains(u'(3+4i)^2=−6.999999999999997+24i')
+
     def test_floating_point_round_error(self):
         self.app.main_view.insert('0.1+0.2=')
         self._assert_result_is(u'0.3')


Follow ups