GMP gives wrong (negative) results
Torbjörn Granlund
tg at gmplib.org
Fri Mar 31 14:55:16 UTC 2017
"V. Nicolai Friedhoff" <vnf at gmx.de> writes:
> 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.
Nope, I said that I am sure, not that I know. But I am very sure because I
[snip]
I took a look at your program and I immediately spotted several bugs (a
syntax error, a handful of memory leaks, and a curious lack of concerns
of precision). So whether you're sure, very sure, or merely know that
your program is correct, to me your program seems pretty buggy...
2.-4. Could I find out if any of this is the case?
I'd say to fix your code first, then look elsewhere.
6. I only include gmp.h and gmpfrxx.h, nothing else.
So you're actually not using GMP's mpf at all, but MPFR's mpf layer?
7. Its a pretty new workstation, so I doubt that :P
OK. Did you consider item 5? :-)
Do you mean regular doubles, without GMP? I tried that and the program
fails much earlier in that case, like at x=5, giving me again large
negative results. The problem I think is that some positive terms in the
sum are too small or large, so they get neglected, while some other
negative terms are valid. This adds up to a negative end result, far from
what the sum should actually be. I would interpret this collective behavior
as a suggestion that my implementation and maths are correct, but somehow
all the platforms get the same issue at largeish numbers (x=5 for c++
doubles, x=30 for GMP, x=120 for Mathematica) with that series.
Isn't a more reasonable conclusion then that you have problems with what
numerical analysts call cancellation, than that "GMP gives wrong
results"?
--
Torbjörn
Please encrypt, key id 0xC8601622
More information about the gmp-discuss
mailing list