mpz_sizeinbase and mpz_root

Kevin Ryde user42@zip.com.au
Sat, 02 Nov 2002 10:00:07 +1000


Jason Moxham <J.L.Moxham@maths.soton.ac.uk> writes:
>
> int mpz_root (mpz_t x , mpz_t y , unsigned long k ) when k=2 does not call the 
> sqrt fn's  which are much faster than general k'th root , I suppose this 
> could be added as small patch , if it was thought that the case k=2 is common 
> enough ?

The general rule is that if an application expects a special case like
that very often it should call mpz_sqrt directly.  But a root like
this is pretty slow anyway so maybe a test could be justified.

> same comment for mpz_sizeinbase(mpz_t x, unsigned long k) when k=2
> by using count_leading_zeros and not the bases[] tables , I was suprised that 
> it was that much faster  , in the current code we have an useless division by 
> 1 , which the compiler doesn't recognize. The case k=2 must be fairly common 
> as it can be used for log_base2 .

If you mean mpz_sizeinbase(x,2) from an application, that can be
recognised for gcc, but not otherwise.

If you mean internally to mpz_sizeinbase, well perhaps an inverse for
the divisor would help, sometimes, if we could be bothered setting
that up.