[gnome-calculator] Fixed special case of serializer returning blank string (fixes #152)



commit dc8aafa166d0d9fde39b6f6910bceb573dcdfa35
Author: Robert Roth <robert roth off gmail com>
Date:   Thu Jun 4 17:09:06 2020 +0300

    Fixed special case of serializer returning blank string (fixes #152)

 lib/serializer.vala      | 5 ++++-
 tests/test-equation.vala | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/lib/serializer.vala b/lib/serializer.vala
index 21bfee4b..8bf3573e 100644
--- a/lib/serializer.vala
+++ b/lib/serializer.vala
@@ -269,7 +269,10 @@ public class Serializer : Object
                 n_digits = n_complex_digits;
             if (s.str == "0" || s.str == "+0" || s.str == "−0")
             {
-                /* Ignore */
+                if (string.str == "")
+                {
+                    string.append ("0"); // real component is empty, the imaginary very small, we shouldn't 
return blank
+                }
             }
             else if (s.str == "1")
             {
diff --git a/tests/test-equation.vala b/tests/test-equation.vala
index cc4e6db4..f5949243 100644
--- a/tests/test-equation.vala
+++ b/tests/test-equation.vala
@@ -631,6 +631,7 @@ private void test_equations ()
     test ("(−1)^0.5", "i", 0);
     test ("√−4", "2i", 0);
     test ("e^iπ", "−1", 0);
+    test ("e^iπ+1", "0", 0);
     test ("log (−10) − (1 + πi÷ln(10))", "0", 0);
     test ("ln (−e) − (1 + πi)", "0", 0);
     test ("sin(iπ÷4) − i×sinh(π÷4)", "0", 0);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]