1

I'm just starting with MPIR and I'm executing this code:

mpf_t t2;
mpf_init2(t2, 10000);
mpf_set_d(t2, 5.999999999999);
gmp_printf("fixed point mpf %.40Ff", t2);

The output is:

fixed point mpf 5.9999999999989999110994176589883863925934

This seems highly innacurate, although I've set the precision to 10000. Am I doing something wrong?

4

1 回答 1

4

5.999999999999是一个double。现在,adouble实际上不能保存值 5.999999999999,但它可以保存值 5.9999999999989999110994176589883863925934,这几乎完全相同 - 你永远不会注意到差异,对吧?

改用mpf_set_str

mpf_set_str(t2, "5.999999999999", 10);

(10 是底数,在这种情况下是十进制)

于 2016-02-02T03:30:37.987 回答