Is there a way to get the number of bits in an mpz_t?

Chris Saunders evas at mountaincable.net
Tue Sep 22 11:54:27 CEST 2009


I haven't tested this much yet but what you suggested seems to be working. 
To explain, what I'm working on is an interface from the Eiffel language to 
the GMP and MPFR libraries.  In my MPZ class I'm providing two division 
functions.  One that does integer division and another that converts the 
arguments to mpfr_t's and returns an mpfr_t.  So I needed to convert an MPZ 
class to an MPFR class and wanted to use mpfr_init2 to initialize the result 
of the division function and also to convert its arguments.  Hence I needed 
to know the nuber of bits in the MPZ objects.  You have been very helpful to 
me and I want to be sure you know it has been appreciated.  I used to be a 
pretty good C programmer but have not been programming in it for many years 
now and my knowledge is really slipping.

Regards
Chris Saunders

----- Original Message ----- 
From: "Sisyphus" <sisyphus1 at optusnet.com.au>
To: "Chris Saunders" <evas at mountaincable.net>; "GMP-discuss Mailing List" 
<gmp-discuss at gmplib.org>
Sent: Tuesday, September 22, 2009 5:20 AM
Subject: Re: Is there a way to get the number of bits in an mpz_t?


>
> ----- Original Message ----- 
> From: "Chris Saunders" <evas at mountaincable.net>
> To: "Sisyphus" <sisyphus1 at optusnet.com.au>; "GMP-discuss Mailing List" 
> <gmp-discuss at gmplib.org>
> Sent: Tuesday, September 22, 2009 6:52 PM
> Subject: Re: Is there a way to get the number of bits in an mpz_t?
>
>
>> First, thanks very much for the response Rob.  I didn't see how to get 
>> what I was after at first but realized after a minute.  Can I ask you to 
>> confirm that calling mpz_sizeinbase (my_mpz, 2) will return what I'm 
>> looking for.
>
> Yes, that will do it ... assuming I understand correctly what it is that 
> you're "looking for" :-)
>
> For example, it will return '4' for the values 8 to 15 (inclusive).
>
> Cheers,
> Rob 



More information about the gmp-discuss mailing list