A newbie question

Bird, John John.Bird at ca.com
Wed Aug 19 03:26:55 CEST 2009


David - thanks! I believe that is exactly what I need.

Christ - Yes - considered that but from a cursory glance at the src it
appears to be implemented as mpz_sizeinbase(n, 10) (n/10^x)%10
operations. It does appear to handle powers of 2 bases quicker though.

Hans - what you say is true - I just used base 10 for my on paper
equations as I find it easier to cope with mentally.

Thanks,
John

-----Original Message-----
From: gmp-discuss-bounces at gmplib.org
[mailto:gmp-discuss-bounces at gmplib.org] On Behalf Of David Gillies
Sent: Wednesday, August 19, 2009 2:56 AM
To: gmp-discuss at gmplib.org
Subject: Re: A newbie question

On Tue, Aug 18, 2009 at 2:51 AM, Bird, John<John.Bird at ca.com> wrote:
> Thank you all for your responses.
>
> I was using the (n / 10^x) % 10 method already but was hoping that I
> could exploit the fact that gmp stores numbers in an array to somehow
> reduce the amount of work necessary to derive.
> David - I don't have to be using base 10 here. I don't suppose the gmp
> libraries support efficient digit extraction for any power of 2 base?
>
Power of two base digit extraction is still (n/base^x)%base, but that
reduces to right shift and mask, which are much faster primitives.
Look at mpz_fdiv_q_2exp() and mpx_ior().

-- 
David Gillies
San Jose
Costa Ricaq_2exp
_______________________________________________
gmp-discuss mailing list
gmp-discuss at gmplib.org
https://gmplib.org/mailman/listinfo/gmp-discuss



More information about the gmp-discuss mailing list