r15474 - gnucash/trunk/src/engine/test - Do not intentionally divide by zero in test-numeric

Andreas Köhler andi5 at cvs.gnucash.org
Tue Jan 30 20:35:26 EST 2007


Author: andi5
Date: 2007-01-30 20:35:25 -0500 (Tue, 30 Jan 2007)
New Revision: 15474
Trac: http://svn.gnucash.org/trac/changeset/15474

Modified:
   gnucash/trunk/src/engine/test/test-numeric.c
Log:
Do not intentionally divide by zero in test-numeric

Random numbers are 0 sometimes, especially on systems with smaller
RAND_MAX. Do not use it as divisor and repeat the run when we hit one.


Modified: gnucash/trunk/src/engine/test/test-numeric.c
===================================================================
--- gnucash/trunk/src/engine/test/test-numeric.c	2007-01-31 00:13:48 UTC (rev 15473)
+++ gnucash/trunk/src/engine/test/test-numeric.c	2007-01-31 01:35:25 UTC (rev 15474)
@@ -221,6 +221,9 @@
 		mult = rand() / 2;
 		numer = rand() / 2;
 
+		/* avoid 0 */
+		if (deno == 0 || mult == 0) { i--; continue; }
+
 		val = gnc_numeric_create (numer, deno);
 		mval = gnc_numeric_create (numer*mult, deno*mult);
 		
@@ -632,6 +635,9 @@
 		gint64 nb = rand();
 		gint64 ne;
 
+		/* avoid 0 */
+		if (nb == 0) { i--; continue; }
+
 		/* avoid overflow; */
 		na /= 2;
 		nb /= 2;



More information about the gnucash-changes mailing list