You are setting it to the double 0.1, which only has 53 bits precision. You can't get more precision than you put in.
Try setting it to 0.5 first (which can be represented exactly in binary), and then divide by the integer 5, which is also able to be represented exactly in binary. Then you will get the 128 bits you are after. By the way, the mpf module isn't used much any more. You should look into mpfr (mpfr.org) instead, which is quite often much faster, and has more functionality and development effort. Bill. On Mon, 10 Aug 2020 at 08:32, wei zhao <zwleopard....@gmail.com> wrote: > > hi all, > > I wrote a simple code to test mpir and found a strange thing. > > the code is > > mpf_t a; > mpf_init2(a, 128); > mpf_set_d(a, 0.1); > > mp_exp_t exp; > char str[256]; > mpf_get_str(str, &exp, 10, 128, a); > I checked str, and it was "1000000000000000055511151231257827021182" instead > of "1000000000000000000000000000000000000000". > > anybody knows why? Does not it affect the computation precision? how can I > make the variable more accurate? > > thansk a lot > > wei > > -- > You received this message because you are subscribed to the Google Groups > "mpir-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to mpir-devel+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/mpir-devel/4dca16b4-7b7d-4a16-91c6-834def1f8f97o%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "mpir-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to mpir-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/mpir-devel/CAB0xFnusL_Hw%3D6%2BizH8t9U4GjHjNDXJ9h5kmK_oQhq%3DX2uqP_w%40mail.gmail.com.