gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Sun Jun 8 15:45:39 EDT 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/8d723f1b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/0fc71ed4 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/8c89c135 (commit)
	from  https://github.com/Gnucash/gnucash/commit/840feccb (commit)



commit 8d723f1b1e8cb21ec39e480a34ac69afd4d892cf
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Jun 8 13:46:56 2014 -0700

    double_to_gnc_numeric: Return overflow error immediately on invalid input.
    
    Which is either nan or outside the range that gnc_numeric supports.
    Also extend the powten array to support the full range of gnc_numeric.

diff --git a/src/libqof/qof/gnc-numeric.c b/src/libqof/qof/gnc-numeric.c
index b9c12e0..96ef3c2 100644
--- a/src/libqof/qof/gnc-numeric.c
+++ b/src/libqof/qof/gnc-numeric.c
@@ -42,13 +42,15 @@
 static const gint64 pten[] = { 1, 10, 100, 1000, 10000, 100000, 1000000,
 			       10000000, 100000000, 1000000000, 10000000000,
 			       100000000000, 1000000000000, 10000000000000,
-			       100000000000000, 10000000000000000};
+			       100000000000000, 10000000000000000,
+			       100000000000000000, 1000000000000000000,
+			       10000000000000000000};
 #define POWTEN_OVERFLOW -5
 
 static inline gint64
 powten (int exp)
 {
-    if (exp > 16 || exp < -16)
+    if (exp > 19 || exp < -19)
 	return POWTEN_OVERFLOW;
     return exp < 0 ? -pten[-exp] : pten[exp];
 }
@@ -1162,6 +1164,9 @@ double_to_gnc_numeric(double in, gint64 denom, gint how)
     double logval;
     double sigfigs;
 
+    if (isnan (in) || fabs (in) > 1e18)
+	return gnc_numeric_error (GNC_ERROR_OVERFLOW);
+
     if ((denom == GNC_DENOM_AUTO) && (how & GNC_HOW_DENOM_SIGFIG))
     {
         if (fabs(in) < 10e-20)

commit 0fc71ed4c7ba068881518449331dd859bbd6482b
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Jun 8 13:43:10 2014 -0700

    Use more significant digits for SX function returns.
    
    gnc_sxed_check_consistent() was failing to balance mortgage payments with
    large payments or small interest amounts because of rounding errors with
    only 6 significant digits. Using 18 causes values < 1 to overflow, so I
    compromised on 12.
    
    Also log an error and return NULL if there's an overflow, since the value
    won't be useful.

diff --git a/src/app-utils/gnc-exp-parser.c b/src/app-utils/gnc-exp-parser.c
index fb966e2..c4cae40 100644
--- a/src/app-utils/gnc-exp-parser.c
+++ b/src/app-utils/gnc-exp-parser.c
@@ -339,7 +339,15 @@ func_op(const char *fname, int argc, void **argv)
     result = g_new0( gnc_numeric, 1 );
     *result = double_to_gnc_numeric( scm_to_double(scmTmp),
                                      GNC_DENOM_AUTO,
-                                     GNC_HOW_DENOM_SIGFIGS(6) | GNC_HOW_RND_ROUND_HALF_UP );
+                                     GNC_HOW_DENOM_SIGFIGS(12) | GNC_HOW_RND_ROUND_HALF_UP );
+    if (gnc_numeric_check (*result) != GNC_ERROR_OK)
+    {
+	PERR("Attempt to convert %f to GncNumeric Failed: %s",
+	     scm_to_double(scmTmp),
+	     gnc_numeric_errorCode_to_string (gnc_numeric_check (*result)));
+	g_free (result);
+	return NULL;
+    }
     /* FIXME: cleanup scmArgs = scm_list, cons'ed cells? */
     return (void*)result;
 }

commit 8c89c1357ed706f0ea4df055d9c311db7a77c78b
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Jun 8 13:29:56 2014 -0700

    725366 - Formula Parsing Error with Scheduled Mortgage Transactions
    
    Clamp per to nper so that the random value from gnc_sxed_check_consistent
    doesn't create overflows with ridiculous values.

diff --git a/src/scm/fin.scm b/src/scm/fin.scm
index 464f879..d30cc85 100644
--- a/src/scm/fin.scm
+++ b/src/scm/fin.scm
@@ -33,26 +33,22 @@
 ;; interest payment amount:
 (define (gnc:ipmt rate per nper pv fv type)
   (* -1 (* rate
-           (- 0 (calc-principal pv
-                                (calc-pmt rate nper pv fv type)
-                                rate (- per 1)))
-        ))
+	   (- 0 (calc-principal pv
+				(calc-pmt rate nper pv fv type)
+				rate (- (if (> per nper) nper per) 1)))))
 )
 
 ;; principal payment amount:
 (define (gnc:ppmt rate per nper pv fv type)
   (let* ((pmt (calc-pmt rate nper pv fv type))
-         (ipmt (* rate
-                  (calc-principal pv pmt rate (- per 1)))))
-    (* -1 (-
-           pmt
-           (* -1 ipmt))))
+         (ipmt (gnc:ipmt rate per nper pv fv type)))
+    (* -1 (- pmt (* -1 ipmt))))
 )
 
 ;; payment amount:
 (define (gnc:pmt rate nper pv fv type)
-  (* -1 (calc-pmt rate nper pv fv type)))
-
+  (* -1 (calc-pmt rate nper pv fv type))
+)
 
 ;; 2 functions from http://lists.gnucash.org/pipermail/gnucash-user/2005-February/012964.html
 ;; future value of deposits with compound interests:



Summary of changes:
 src/app-utils/gnc-exp-parser.c | 10 +++++++++-
 src/libqof/qof/gnc-numeric.c   |  9 +++++++--
 src/scm/fin.scm                | 18 +++++++-----------
 3 files changed, 23 insertions(+), 14 deletions(-)



More information about the gnucash-changes mailing list