testing value of last digit of an integer.

Décio Luiz Gazzoni Filho decio at decpp.net
Sun Apr 4 22:58:12 CEST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sunday 04 April 2004 15:25, David McKen wrote:
> I see.
>
> I was hoping to optimize a function.
>
> Guess I have to look elsewhere in the algorithm for optimizations.

You can save some time (perhaps half of it, if the integer in question is 
random) by checking whether the integer is even, for instance with the 
function mpz_even_p. In binary this operation requires looking only at the 
last bit of the integer, so it's very fast.

Décio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAcHcGFXvAfvngkOIRAvuyAJ96joITx/YRcRvjhFwn3ctF3Ok6EgCfQfvs
QoDsOPnHL3Rp7A8CBoMnHTc=
=IKqd
-----END PGP SIGNATURE-----


More information about the gmp-discuss mailing list