Squaring Question

Digital Parasite digital.parasite at gmail.com
Thu Feb 19 18:52:14 CET 2009


If I need to square a value many times in a loop, is using mpz_mul the
fastest way in GMP to achieve this or is there another function that
is better specifically for squaring?

For example, some sample code below:

// r = 6
mpz_set_ui(r,6);
// q = 350000
mpz_set_ui(q,6);
// p = 2^q so in this case 350000 bits

for (j=1; j <= mpz_get_ui(q); j++)
{
	// t = r^2 - 2
	mpz_mul(t, r, r);
	mpz_sub_ui(t, t, 2);
	// r = t | p
	mpz_mod(r, t, p);
}

Thank you in advance.


More information about the gmp-discuss mailing list