fastest way to square a number?

Paul Zimmermann Paul.Zimmermann at
Tue Nov 11 08:49:53 CET 2008

> what is the recommended way to square a number in GMP? Do I need to
> call mpn_sqr_basecase directly?

GMP automagically recognizes when you want to compute a square. This is done
by comparing pointers in mpz_mul, mpf_mul, mpq_mul and mpn_mul, which costs
only O(1) and is thus very cheap. Thus the answer to your question is simply
call mpz_mul (res, op, op) if you are using mpz for example.

Paul Zimmermann

More information about the gmp-discuss mailing list