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