GMP precision with mpf_set_d

Zimmermann Paul Paul.Zimmermann at loria.fr
Tue Jun 21 19:57:02 CEST 2011


>   	mpf_init2(x, 1000000);
>   	mpf_init2(y, 1000000);
>   	mpf_init2(z, 1000000);
>   	mpf_set_str(x, "1e0", 10);
>   	mpf_set_d(y, 3.3124365842565);
>   	mpf_set_d(z, 3.3124365842566);

if you want 1000000 bits of precision, I suggest you use instead:

       mpf_set_str (y, "3.3124365842565", 10);
       mpf_set_str (z, "3.3124365842566", 10);

as you did for the variable 'x'.

As Torbjörn explained, mpf_set_d(y, 3.3124365842565) assigns to y the
53-bit approximation to the nearest of 3.3124365842565, which is
3729472041636493/1125899906842624. Whatever the precision (>= 53) you use,
you will get that approximation in y. mpf_set_str (y, "3.3124365842565", 10)
in the contrary will put in y a 1000000-bit approximation of 3.3124365842565.

Paul Zimmermann




More information about the gmp-discuss mailing list