Q about GNU GMP mpf_add
bodrato at mail.dm.unipi.it
bodrato at mail.dm.unipi.it
Sat Feb 2 11:26:43 CET 2013
Ciao,
Il Ven, 1 Febbraio 2013 4:27 pm, Paul Reiners ha scritto:
> I have a GNU GMP question, which I've posted on StackOverflow:
The code you posted there is not self-contained.
I had to substitute some functions to test it, I obtained the following:
#include <stdio.h>
#include "gmp.h"
int
main (int argc, char *argv[])
{
mpf_t mpf_first_sum;
mpf_init(mpf_first_sum);
mpf_set_d(mpf_first_sum, 0.01234);
double first_sum = mpf_get_d(mpf_first_sum);
mpf_t mpf_second_sum;
mpf_init(mpf_second_sum);
mpf_set_d(mpf_second_sum, 0.12345);
double second_sum = mpf_get_d(mpf_second_sum);
printf("%f + %f =", first_sum, second_sum);
mpf_t mpf_sum;
mpf_init(mpf_sum);
mpf_add (mpf_sum, mpf_first_sum, mpf_second_sum);
mpf_clear(mpf_first_sum);
mpf_clear(mpf_second_sum);
double sum = mpf_get_d(mpf_sum);
mpf_clear(mpf_sum);
printf(" %f [expected %f]\n", sum, first_sum + second_sum);
return 0;
}
It works as expected.
I guess the problem is hidden inside the functions I substituted with
mpf_set_d.
Regards,
m
--
http://bodrato.it/papers/
More information about the gmp-discuss
mailing list