I am using GMP, and I want to be able to quickly convert an mpz
to an mpf
. I looked through the library and couldn't find much. The best thing I could think of was this:
mpz_t x;
/* Insert code here that assigns some value to x */
char buf[SIZE];
gmp_sprintf(buf, "%Zd", x);
mpf_t y;
mpf_set_str(y, buf);
This solution requires repeated conversion to and from a string. Also, it is limited by SIZE
, and I see no way to predetermine how large SIZE
needs to be. Is there any better way to do this conversion?