mpz_set_ld (set from long double)

Sisyphus sisyphus1 at
Mon Jun 11 12:08:15 CEST 2007

I was trying to come up with a simple and effective way of assigning a long 
double to an mpz_t.

I thought:

First, assign the long double to a string buffer, ie:
sprintf(buffer, "%.0Lf", ld);

And then assign the string to the mpz_t:
mpz_init_set_str(my_mpz_t, buffer, 10);

AFAICT that's both simple and effective - but is there a smarter, less 
computationally-intensive way of achieving the desired result ?


More information about the gmp-discuss mailing list