[Gnucash-changes] handle yet another overflow case in numeric multiplication.

Linas Vepstas linas at cvs.gnucash.org
Tue Jul 6 09:42:40 EDT 2004


Log Message:
-----------
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.

Modified Files:
--------------
    gnucash/src/engine:
        gnc-numeric.c

Revision Data
-------------
Index: gnc-numeric.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-numeric.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -Lsrc/engine/gnc-numeric.c -Lsrc/engine/gnc-numeric.c -u -r1.54 -r1.55
--- src/engine/gnc-numeric.c
+++ src/engine/gnc-numeric.c
@@ -473,6 +473,24 @@
   /* 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 
      * things up for the final value. Else overflow. */


More information about the gnucash-changes mailing list