From 763b1ea01224a223b0112d59636b93eece0a324e Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Tue, 6 Jul 2004 13:42:39 +0000 Subject: [PATCH] handle yet another overflow case in numeric multiplication. Turns out there were common factors between two fractions; by eliminating these first, significant rounding errors can be avoided. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@10169 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/gnc-numeric.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/engine/gnc-numeric.c b/src/engine/gnc-numeric.c index 9973464f17..edc22549b3 100644 --- a/src/engine/gnc-numeric.c +++ b/src/engine/gnc-numeric.c @@ -472,6 +472,24 @@ gnc_numeric_mul(gnc_numeric a, gnc_numeric b, /* If it looks to be overflowing, try to reduce the fraction ... */ if (bignume.isbig || bigdeno.isbig) + { + gint64 tmp; + a = gnc_numeric_reduce (a); + b = gnc_numeric_reduce (b); + tmp = a.num; + a.num = b.num; + b.num = tmp; + a = gnc_numeric_reduce (a); + b = gnc_numeric_reduce (b); + + bignume = mult128 (a.num, b.num); + bigdeno = mult128 (a.denom, b.denom); + product.num = a.num*b.num; + product.denom = a.denom*b.denom; + } + + /* If it its still overflowing, and rounding is allowed then round */ + if (bignume.isbig || bigdeno.isbig) { /* If rounding allowed, then shift until there's no * more overflow. The conversion at the end will fix