gnucash stable: Multiple changes pushed

Mike Alexander mta at code.gnucash.org
Thu May 18 18:38:24 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/71afa3e0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/d61b9629 (commit)
	from  https://github.com/Gnucash/gnucash/commit/5563d535 (commit)



commit 71afa3e0fc7d3b7677908e850565407af45e6b9a
Author: Mike Alexander <mta at umich.edu>
Date:   Thu May 18 17:42:44 2023 -0400

    Make the GncNumeric string constructtor work for long decimal numbers.
    
    It was failing to produce a correct representation for input with more than
    14 digits after the decimal poin.  Fixes Bug 798916.  The bug was in
    powten so this fix may corect other problems too.  For example conversion
    of GncNumeric back to a string also failed in certain circumsances.

diff --git a/libgnucash/engine/gnc-numeric.cpp b/libgnucash/engine/gnc-numeric.cpp
index d0e716c295..7ab1ed2063 100644
--- a/libgnucash/engine/gnc-numeric.cpp
+++ b/libgnucash/engine/gnc-numeric.cpp
@@ -48,9 +48,9 @@ static const int64_t pten[] = { 1, 10, 100, 1000, 10000, 100000, 1000000,
                                INT64_C(10000000000), INT64_C(100000000000),
                                INT64_C(1000000000000), INT64_C(10000000000000),
                                INT64_C(100000000000000),
+                               INT64_C(1000000000000000),
                                INT64_C(10000000000000000),
-                               INT64_C(100000000000000000),
-                               INT64_C(1000000000000000000)};
+                               INT64_C(100000000000000000)};
 #define POWTEN_OVERFLOW -5
 
 int64_t
@@ -175,9 +175,18 @@ GncNumeric::GncNumeric(const std::string& str, bool autoround)
         GncInt128 high((neg && m[1].length() > 1) || (!neg && m[1].length()) ?
                        stoll(m[1].str()) : 0);
         GncInt128 low(stoll(m[2].str()));
-        int64_t d = powten(m[2].str().length());
+        auto exp10 = m[2].str().length();
+        int64_t d = powten(exp10);
         GncInt128 n = high * d + (neg ? -low : low);
-
+        while (exp10 > max_leg_digits)
+        {
+            /* If the arg to powten is bigger than max_leg_digits
+               it returns 10**max_leg_digits so reduce exp10 by
+               that amount */
+            n = n / powten(exp10 - max_leg_digits);
+            exp10 -= max_leg_digits;
+        }
+        
         if (!autoround && n.isBig())
         {
             std::ostringstream errmsg;
diff --git a/libgnucash/engine/test/gtest-gnc-numeric.cpp b/libgnucash/engine/test/gtest-gnc-numeric.cpp
index e194367bbf..27b386748b 100644
--- a/libgnucash/engine/test/gtest-gnc-numeric.cpp
+++ b/libgnucash/engine/test/gtest-gnc-numeric.cpp
@@ -185,6 +185,12 @@ TEST(gncnumeric_constructors, test_string_constructor)
     GncNumeric neg_decimal_frac_nozero("-.12345");
     EXPECT_EQ(-12345, neg_decimal_frac_nozero.num());
     EXPECT_EQ(100000, neg_decimal_frac_nozero.denom());
+    GncNumeric big_denom(".12345678901234567");
+    EXPECT_EQ(12345678901234567, big_denom.num());
+    EXPECT_EQ(100000000000000000, big_denom.denom());
+    GncNumeric too_big_denom(".123456789012345678");
+    EXPECT_EQ(12345678901234567, too_big_denom.num());
+    EXPECT_EQ(100000000000000000, too_big_denom.denom());
 }
 
 TEST(gncnumeric_output, string_output)
diff --git a/libgnucash/engine/test/test-numeric.cpp b/libgnucash/engine/test/test-numeric.cpp
index 41ef28fa08..bf3cd51dd7 100644
--- a/libgnucash/engine/test/test-numeric.cpp
+++ b/libgnucash/engine/test/test-numeric.cpp
@@ -545,8 +545,8 @@ check_add_subtract (void)
 static const gint64 pten[] = { 1, 10, 100, 1000, 10000, 100000, 1000000,
 			       10000000, 100000000, 1000000000, 10000000000,
 			       100000000000, 1000000000000, 10000000000000,
-			       100000000000000, 10000000000000000,
-			       100000000000000000, 1000000000000000000};
+			       100000000000000, 1000000000000000,
+			       10000000000000000, 100000000000000000};
 #define POWTEN_OVERFLOW -5
 
 static inline gint64

commit d61b962954ba20e2e5f5c5da3a28307864a1d069
Author: Mike Alexander <mta at umich.edu>
Date:   Thu May 18 17:34:05 2023 -0400

    Fix a typo in some debug output.

diff --git a/libgnucash/app-utils/gnc-quotes.cpp b/libgnucash/app-utils/gnc-quotes.cpp
index 3003fca71f..1b8246cf2e 100644
--- a/libgnucash/app-utils/gnc-quotes.cpp
+++ b/libgnucash/app-utils/gnc-quotes.cpp
@@ -569,7 +569,7 @@ parse_quote_json(PriceParams& p, const bpt::ptree& comm_pt)
     PINFO("     Time: %s", (p.time ? p.time->c_str() : "missing"));
     PINFO(" Currency: %s", (p.currency ? p.currency->c_str() : "missing"));
     PINFO("    Price: %s", (p.price ? p.price->c_str() : "missing"));
-    PINFO(" Inverted: %s\n", (inverted ? "yes" : "no"));
+    PINFO(" Inverted: %s\n", (p.inverted ? "yes" : "no"));
 }
 
 static time64



Summary of changes:
 libgnucash/app-utils/gnc-quotes.cpp          |  2 +-
 libgnucash/engine/gnc-numeric.cpp            | 17 +++++++++++++----
 libgnucash/engine/test/gtest-gnc-numeric.cpp |  6 ++++++
 libgnucash/engine/test/test-numeric.cpp      |  4 ++--
 4 files changed, 22 insertions(+), 7 deletions(-)



More information about the gnucash-changes mailing list