Division problems

Torbjorn Granlund tg at gmplib.org
Thu Nov 5 08:09:53 CET 2009


David Topper <djtopper at gmail.com> writes:

  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);
  
So, are you saying that you passed e.g. 21260088135 and 108696304 as
dividend and divisor to mpz_divexact?  This is outside mpz_divexact's
defined operands, since clearly the even number 108696304 does not
divide the odd number 21260088135.

What do you to do? A plain, division, say floor(a/b), or ceil(a/b)?

Then please check out this:
http://gmplib.org/manual/Integer-Division.html

-- 
Torbjörn


More information about the gmp-discuss mailing list