GMP gives wrong (negative) results

Torbjörn Granlund tg at
Fri Mar 31 10:10:24 UTC 2017

"V. Nicolai Friedhoff" <vnf at> writes:

  For small values of x<29 the results seem to be correct, so I am sure that
  my maths and my implementation is correct. But for larger x>29 the results
  are wrong and even negative (the function should be positive for positive
Let me rephrase that: your program is correct for some parameters,
therefore you know it is correct for all parameters.

Skeptical programmers might not find that reasoning convincing.

  What is wrong when GMP gives me negative results for a function that should
  be positive once some numbers become large?
That can have many causes, with varying degree of likelihood:

1. The user's program is buggy
2. There is a bug in GMP
3. There is a bug in the compiler used for compiling GMP
4. There is a bug in the compiler used for compiling the user code
6. There is a bug in some other explicitly or implicitly used library
7. There are hardware problems
8. This list lacks one or more items

If I were to debug a float application with apparent stability issues,
I'd start with plain old 'double' variables.

Please encrypt, key id 0xC8601622

More information about the gmp-discuss mailing list