Obtaining the number of mantissa bits in use by an mpf
John Westwood
john at westwoodsolutions.com
Fri May 14 14:28:56 CEST 2010
Hello GMP gurus!
I was wondering if you could help me with my problem. I wish to be able to
obtain the numbers of mantissa bits in use by an mpf variable. In the manual,
near the beginning of chapter 7, it states:
"Each variable keeps a size for the mantissa data actually in use. This means
that if a float is exactly represented in only a few bits then only those bits
will be used in a calculation, even if the selected precision is high."
I would to retrieve this size, but I see no function for doing so. The mpz
variable has an mpz_sizeinbase function, but I see no equivalent for mpf.
I have tried using the mpf_get_str function, but the returned char array is
longer than I expect. This is what I tried:
long exponent;
char* string = mpf_get_str(NULL, &exponent, 2, 0, delta);
precision = strlen(string);
I wish to know the number of bits in use, so that I can determine when to
increase the precision of my mpf variables. At low precisions I use doubles
and I determine the precision being used with:
precision = static_cast<unsigned long>( fabs(log(delta) / log(2.0)) );
I cannot use this method for arbitrary precision, because GMP has no log
function.
My program is a fractal explorer, hence why I only wish to use adequate
precision at a particular magnification.
Thanks,
John
More information about the gmp-discuss
mailing list