From 8c89c1357ed706f0ea4df055d9c311db7a77c78b Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 8 Jun 2014 13:29:56 -0700 Subject: [PATCH] 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. --- src/scm/fin.scm | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/scm/fin.scm b/src/scm/fin.scm index 464f879077..d30cc85803 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: