r16716 - gnucash/trunk/src/engine - (#492137) Re-apply r16619 and make a change to the test

Derek Atkins warlord at cvs.gnucash.org
Mon Dec 24 16:18:09 EST 2007


Author: warlord
Date: 2007-12-24 16:18:09 -0500 (Mon, 24 Dec 2007)
New Revision: 16716
Trac: http://svn.gnucash.org/trac/changeset/16716

Modified:
   gnucash/trunk/src/engine/cap-gains.c
   gnucash/trunk/src/engine/test-core/test-engine-stuff.c
Log:
(#492137) Re-apply r16619 and make a change to the test
harness to actually get the checks to pass with r16690.
This was an overflow in the test harness.

Modified: gnucash/trunk/src/engine/cap-gains.c
===================================================================
--- gnucash/trunk/src/engine/cap-gains.c	2007-12-24 20:28:02 UTC (rev 16715)
+++ gnucash/trunk/src/engine/cap-gains.c	2007-12-24 21:18:09 UTC (rev 16716)
@@ -168,7 +168,7 @@
 static inline GNCLot *
 xaccAccountFindOpenLot (Account *acc, gnc_numeric sign, 
    gnc_commodity *currency,
-   guint64 guess,
+   gint64 guess,
    gboolean (*date_pred)(Timespec, Timespec))
 {
    struct find_lot_s es;
@@ -195,7 +195,7 @@
           sign.denom);
       
    lot = xaccAccountFindOpenLot (acc, sign, currency,
-                   G_MAXUINT64, earliest_pred);
+                   G_MAXINT64, earliest_pred);
    LEAVE ("found lot=%p %s baln=%s", lot, gnc_lot_get_title (lot),
                gnc_num_dbg_to_string(gnc_lot_get_balance(lot)));
    return lot;
@@ -210,7 +210,7 @@
 	  sign.num, sign.denom);
       
    lot = xaccAccountFindOpenLot (acc, sign, currency,
-                   0, latest_pred);
+                   G_MININT64, latest_pred);
    LEAVE ("found lot=%p %s", lot, gnc_lot_get_title (lot));
    return lot;
 }

Modified: gnucash/trunk/src/engine/test-core/test-engine-stuff.c
===================================================================
--- gnucash/trunk/src/engine/test-core/test-engine-stuff.c	2007-12-24 20:28:02 UTC (rev 16715)
+++ gnucash/trunk/src/engine/test-core/test-engine-stuff.c	2007-12-24 21:18:09 UTC (rev 16716)
@@ -447,9 +447,9 @@
     }
     else
     {
-       gint64 norm = RAND_IN_RANGE (8ULL);
+       gint64 norm = RAND_IN_RANGE (7ULL);
 
-       /* multiple of 10, between 1 and 10 million */
+       /* multiple of 10, between 1 and 1 million */
        deno = 1;
        while (norm) 
        {
@@ -460,8 +460,14 @@
 
     /* Arbitrary random numbers can cause pointless overflow 
      * during calculations.  Limit dynamic range in hopes 
-     * of avoiding overflow. */
-    numer = get_random_gint64()/1000000;
+     * of avoiding overflow. Right now limit it to approx 2^48.
+     * The initial division is to help us down towards the range.
+     * The loop is to "make sure" we get there.  We might
+     * want to make this dependent on "deno" in the future.
+     */
+    do {
+      numer = get_random_gint64()/1000000;
+    } while ((numer >> 31) > 0x1FFFF);
     if (0 == numer) numer = 1;
     /* Make sure we have a non-zero denominator */
     if (0 == deno) deno = 1;



More information about the gnucash-changes mailing list