Je suis en train de calculer Pi à l'aide GMP (5.1.0) avec cette série: Calcul de Pi en utilisant GMP
Qu'est-ce que je l'ai fait est:
#include <stdio.h>
#include <gmp.h>
mpz_t pi;
mpz_t next; // Every number in the serie that comes after 3
int a = 2, b = 3, c = 4; // Divisors. Everytime add 2 to all of them at the end of the loop
int i; // Loop counter
int main (void) {
mpz_init (pi); mpz_init (next);
mpz_set_str (pi, "3", 10);
for (i = 2 ;; ++i) {
printf ("%s\n", mpz_get_str (NULL, 10, pi));
mpz_set_d (next, 4/(a * b * c));
if (i % 2 == 0)
mpz_add (pi, pi, next);
else
mpz_sub (pi, pi, next);
a += 2; b += 2; c += 2;
}
mpz_clear (next);
mpz_clear (pi);
}
Je suis compilation sur Linux 64 bits:
gcc -Wall -pedantic -o foo foo.c -lgmp
Sortie:
3
3
3
and so on
Résultats escomptés:
3
3.1666...
3.1333...
3.1452...
3.1396...
and so on
Toute aide sera grandement appréciée.
Quel débogage avez-vous fait jusqu'à présent? –
Vous effectuez tous ces calculs à l'aide de grands entiers et imprimez une valeur entière. D'où viennent les valeurs décimales? – talonmies