Initialise an integer with all bits set to 1.
DTAshley@aol.com
DTAshley@aol.com
Mon, 30 Jun 2003 23:23:01 EDT
--part1_178.1d08e172.2c325895_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
In a message dated 6/30/2003 7:05:27 PM Eastern Daylight Time,
user42@zip.com.au writes:
> "Sisyphus" <kalinabears@iinet.net.au> writes:
> >
> >At the moment I'm initialising the integer to zero with
> >mpz_init2() and then looping through each bit and setting it to 1 with
> >mpz_setbit().
>
> A value 2^n-1 can be done in the expected way with mpz_set_ui(z,1),
> mpz_mul_2exp(z,z,n) and mpz_sub_ui(z,z,1). Should be faster than
> mpz_setbit, especially since the latter probably ends up doing
> repeated reallocs.
Hmmm ... the obvious question is whether this scenario is common enough to
make a special function call, something like:
mpz_assign_repeating_limb_pattern(mpz_t victim, unsigned long
*repeating_pattern_array, unsigned pattern_array_length, unsigned nbits)
Y'all get the idea, I'm sure.
Dave.
--part1_178.1d08e172.2c325895_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable
<HTML><FONT FACE=3Darial,helvetica><FONT SIZE=3D2 FAMILY=3D"SANSSERIF" FACE=
=3D"Arial" LANG=3D"0">In a message dated 6/30/2003 7:05:27 PM Eastern Daylig=
ht Time, user42@zip.com.au writes:<BR>
<BR>
<BLOCKQUOTE TYPE=3DCITE style=3D"BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT=
: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">"Sisyphus" <kalinabears@iine=
t.net.au> writes:<BR>
><BR>
>At the moment I'm initialising the integer to zero with<BR>
>mpz_init2() and then looping through each bit and setting it to 1 with<B=
R>
>mpz_setbit().<BR>
<BR>
A value 2^n-1 can be done in the expected way with mpz_set_ui(z,1),<BR>
mpz_mul_2exp(z,z,n) and mpz_sub_ui(z,z,1). Should be faster than<BR>
mpz_setbit, especially since the latter probably ends up doing<BR>
repeated reallocs.</BLOCKQUOTE><BR>
<BR>
Hmmm ... the obvious question is whether this scenario is common enough to m=
ake a special function call, something like:<BR>
<BR>
mpz_assign_repeating_limb_pattern(mpz_t victim, unsigned long *repeating_pat=
tern_array, unsigned pattern_array_length, unsigned nbits)<BR>
<BR>
Y'all get the idea, I'm sure.<BR>
<BR>
Dave.</FONT></HTML>
--part1_178.1d08e172.2c325895_boundary--