Obtaining the number of mantissa bits in use by an mpf

Torbjorn Granlund tg at gmplib.org
Fri May 14 14:52:59 CEST 2010


John Westwood <john at westwoodsolutions.com> writes:

  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.
  
There is no way, since we didn't see the need.

As mpf works, the same number could be stored in different ways, i.e.,
the number 17 could take 128 bits after one calculation and 64 bits
after another.

You may get the *precision* used for calculations whose result is
written to a variable using mpf_get_prec.

  I cannot use this method for arbitrary precision, because GMP has no log 
  function.
  
You may want to look into mpfr.  It is an add-on package for GMP which
the GMP developers recommend.

-- 
Torbjörn


More information about the gmp-discuss mailing list