Division problems

David Topper djtopper at gmail.com
Thu Nov 5 00:16:57 CET 2009


I'm getting some bizarre and seemingly random division errors on my
MacBook Pro (2.8ghz) running Mac OS 10.5.8 and gcc version 4.0.1
(Apple Inc. build 5490).  I did the standard install of gmp.

Simply put, I'm dividing numbers from i to n, then decreasing n if
certain conditions are met.  So here are some examples of errors:

21260088135 / 108696304 = 15690273043697746481
20408568497 / 113625893 = 137947138210572115
19916152035 / 116419633 = 15638490038839055151

I'm at a loss.  Here's my snippet of code:

	mpz_set(pTemp,pEnd);
	
	mpz_divexact(pEnd,pTest,j);

	if (mpz_cmp(pEnd,pTemp)>0) {
		gmp_printf("%Zd / %Zd = %Zd\n",pTemp,j,pEnd);
		gmp_printf("((%d - %Zd) DIVISION ERROR!\n",exp,pTest);
	}

I've tried resetting variables and the rest, but nothing seems to
help.  I'm sure this has been documented before and I must be missing
something very simple.

Thanks,

D


More information about the gmp-discuss mailing list