/* test_mpf.c */ /* gcc -o test_mpf -I. test_mpf.c -L. -lgmp */ #include #include "gmp.h" int main() { mpf_t one, denom, row, sum; mpf_t quo, fract; mp_exp_t exp; char my_str[100000]; int i, j, k; mpf_init(one); /* must init every variable */ mpf_init(sum); mpf_init(denom); mpf_init(row); mpf_init(quo); mpf_init(fract); mpf_set_str(one, "1.0", 10); mpf_set_str(row, "0", 10); mpf_set(sum, one); mpf_set(denom, one); printf("test_mpf using mpf \n"); for(j=0; j<10; j++) { printf("j=%d \n", j); for(i=0; i<10; i++) { mpf_add(row, row, one); mpf_add(denom, denom, row); mpf_set(quo, one); mpf_add(sum, sum, quo); } mpf_get_str(my_str, &exp, 10, 0, sum); printf("sum = %s, exp=%d \n", my_str, exp); } mpf_set_str(fract, "123.45678E+27", 10); mpf_get_str(my_str, &exp, 10, 0, fract); printf(" num = 123.45678E+27 \n"); printf("fract = %s, exp=%d \n", my_str, exp); printf("value = .%sE%d \n", my_str, exp); return 0; }