Skip to content

Commit

Permalink
[commodity-utils] use scheme division instead of gnc-numeric
Browse files Browse the repository at this point in the history
with small change to test due to increased precision
  • Loading branch information
christopherlam committed May 3, 2019
1 parent f2aacf9 commit e111c5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
43 changes: 12 additions & 31 deletions gnucash/report/report-system/commodity-utilities.scm
Expand Up @@ -306,14 +306,6 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
pricelist))
(earlier (and (not (null? earlierlist))
(last earlierlist))))
;; (if earlier
;; (warn "earlier"
;; (qof-print-date (car earlier))
;; (gnc-numeric-to-double (cadr earlier))))
;; (if later
;; (warn "later"
;; (qof-print-date (car later))
;; (gnc-numeric-to-double (cadr later))))

(if (and earlier later)
(if (< (abs (- date (car earlier)))
Expand Down Expand Up @@ -637,11 +629,8 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
(map
(lambda (e)
(list (car e)
(abs
(gnc-numeric-div ((cdadr e) 'total #f)
((caadr e) 'total #f)
GNC-DENOM-AUTO
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)))))
(abs (/ ((cdadr e) 'total #f)
((caadr e) 'total #f)))))
(gnc:get-exchange-totals report-commodity end-date)))

(define (gnc:make-exchange-cost-alist report-commodity end-date)
Expand All @@ -651,12 +640,10 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
(map
(lambda (e)
(list (car e)
(if (zero? ((caadr e) 'total #f)) 0
(abs
(gnc-numeric-div ((cdadr e) 'total #f)
((caadr e) 'total #f)
GNC-DENOM-AUTO
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))))))
(if (zero? ((caadr e) 'total #f))
0
(abs (/ ((cdadr e) 'total #f)
((caadr e) 'total #f))))))
(gnc:get-exchange-cost-totals report-commodity end-date)))


Expand Down Expand Up @@ -718,10 +705,8 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
(if (or (not pair)
(zero? foreign-amount))
0
(gnc-numeric-mul foreign-amount
(cadr pair)
(gnc-commodity-get-fraction domestic)
GNC-RND-ROUND)))))))))
(* foreign-amount
(cadr pair))))))))))

;; Helper for the gnc:exchange-by-pricalist* below. Exchange the
;; <gnc:monetary> 'foreign' into the <gnc:commodity*> 'domestic' by
Expand All @@ -734,10 +719,8 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
(gnc:make-gnc-monetary
domestic
(if price-value
(gnc-numeric-mul (gnc:gnc-monetary-amount foreign)
price-value
(gnc-commodity-get-fraction domestic)
GNC-RND-ROUND)
(* (gnc:gnc-monetary-amount foreign)
price-value)
(begin
(warn "gnc:exchange-by-pricevalue-helper: No price found for "
(gnc:monetary->string foreign) " into "
Expand All @@ -758,10 +741,8 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
domestic
(if price
(let ((result
(gnc-numeric-mul (gnc:gnc-monetary-amount foreign)
(gnc-price-get-value price)
(gnc-commodity-get-fraction domestic)
GNC-RND-ROUND)))
(* (gnc:gnc-monetary-amount foreign)
(gnc-price-get-value price))))
(gnc-price-unref price)
result)
(begin
Expand Down
2 changes: 1 addition & 1 deletion gnucash/report/report-system/test/test-commodity-utils.scm
Expand Up @@ -697,7 +697,7 @@
(gnc-dmy2time64-neutral 20 02 2016)
#f #f)))
(test-equal "gnc:case-exchange-time-fn average-cost 20/02/2012"
8073/100
14127/175
(gnc:gnc-monetary-amount
(exchange-fn
(gnc:make-gnc-monetary AAPL 1)
Expand Down

0 comments on commit e111c5b

Please sign in to comment.