gnucash maint: Handle very large denominators in precies from Finance::Quote
Mike Alexander
mta at code.gnucash.org
Mon Aug 30 03:46:24 EDT 2021
Updated via https://github.com/Gnucash/gnucash/commit/0c21ae35 (commit)
from https://github.com/Gnucash/gnucash/commit/e13644df (commit)
commit 0c21ae35221b49c640d1025d66ea024e24db15c2
Author: Mike Alexander <mta at umich.edu>
Date: Mon Aug 30 03:09:23 2021 -0400
Handle very large denominators in precies from Finance::Quote
The OpenExchange exchange rate source in Finance::Quote produces
some ridiculously precise prices like #e6.95253159056541e-5 which
produce a denominator greater than INT64_MAX. Use the rationalize
function to bring them back to reality.
diff --git a/gnucash/price-quotes.scm b/gnucash/price-quotes.scm
index 2c6375585..8e3ff255f 100644
--- a/gnucash/price-quotes.scm
+++ b/gnucash/price-quotes.scm
@@ -346,7 +346,13 @@
(cond
((assq-ref quote-data (car price-syms)) =>
(lambda (p)
- (set! price (gnc-scm-to-numeric p))
+ ;; The OpenExchange exchange rate source in Finance::Quote produces
+ ;; some ridiculously precise prices like #e6.95253159056541e-5 which
+ ;; produce a denominator greater than INT64_MAX. Use the rationalize
+ ;; function to bring them back to reality. The precision parameter is
+ ;; chosen empirically to give the best results.
+ (set! price (gnc-scm-to-numeric
+ (rationalize p 1/100000000000000)))
(set! price-type (car price-types))))
(else (lp (cdr price-syms) (cdr price-types))))))
Summary of changes:
gnucash/price-quotes.scm | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
More information about the gnucash-changes
mailing list